Skip to content

Commit 8ca6da8

Browse files
authored
fix(vue): Merge default and manual hooks while creating mixins. (#4132)
1 parent 89156a4 commit 8ca6da8

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

packages/vue/src/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Operation } from './types';
2+
3+
export const DEFAULT_HOOKS: Operation[] = ['activate', 'mount', 'update'];

packages/vue/src/sdk.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { init as browserInit, SDK_VERSION } from '@sentry/browser';
22
import { getGlobalObject, logger } from '@sentry/utils';
33

4+
import { DEFAULT_HOOKS } from './constants';
45
import { attachErrorHandler } from './errorhandler';
56
import { createTracingMixins } from './tracing';
67
import { Options, TracingOptions, Vue } from './types';
@@ -9,7 +10,7 @@ const DEFAULT_CONFIG: Options = {
910
Vue: getGlobalObject<{ Vue: Vue }>().Vue,
1011
attachProps: true,
1112
logErrors: false,
12-
hooks: ['activate', 'mount', 'update'],
13+
hooks: DEFAULT_HOOKS,
1314
timeout: 2000,
1415
trackComponents: false,
1516
_metadata: {

packages/vue/src/tracing.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Span, Transaction } from '@sentry/types';
33
import { logger, timestampInSeconds } from '@sentry/utils';
44

55
import { formatComponentName } from './components';
6+
import { DEFAULT_HOOKS } from './constants';
67
import { Hook, Operation, TracingOptions, ViewModel, Vue } from './types';
78

89
type Mixins = Parameters<Vue['mixin']>[0];
@@ -47,7 +48,10 @@ function finishRootSpan(vm: VueSentry, timestamp: number, timeout: number): void
4748
}
4849

4950
export const createTracingMixins = (options: TracingOptions): Mixins => {
50-
const { hooks } = options;
51+
const hooks = (options.hooks || [])
52+
.concat(DEFAULT_HOOKS)
53+
// Removing potential duplicates
54+
.filter((value, index, self) => self.indexOf(value) === index);
5155

5256
const mixins: Mixins = {};
5357

0 commit comments

Comments
 (0)