Skip to content

fix(vue): Merge default and manual hooks while creating mixins. #4132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/vue/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Operation } from './types';

export const DEFAULT_HOOKS: Operation[] = ['activate', 'mount', 'update'];
3 changes: 2 additions & 1 deletion packages/vue/src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { init as browserInit, SDK_VERSION } from '@sentry/browser';
import { getGlobalObject, logger } from '@sentry/utils';

import { DEFAULT_HOOKS } from './constants';
import { attachErrorHandler } from './errorhandler';
import { createTracingMixins } from './tracing';
import { Options, TracingOptions, Vue } from './types';
Expand All @@ -9,7 +10,7 @@ const DEFAULT_CONFIG: Options = {
Vue: getGlobalObject<{ Vue: Vue }>().Vue,
attachProps: true,
logErrors: false,
hooks: ['activate', 'mount', 'update'],
hooks: DEFAULT_HOOKS,
timeout: 2000,
trackComponents: false,
_metadata: {
Expand Down
6 changes: 5 additions & 1 deletion packages/vue/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Span, Transaction } from '@sentry/types';
import { logger, timestampInSeconds } from '@sentry/utils';

import { formatComponentName } from './components';
import { DEFAULT_HOOKS } from './constants';
import { Hook, Operation, TracingOptions, ViewModel, Vue } from './types';

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

export const createTracingMixins = (options: TracingOptions): Mixins => {
const { hooks } = options;
const hooks = (options.hooks || [])
.concat(DEFAULT_HOOKS)
// Removing potential duplicates
.filter((value, index, self) => self.indexOf(value) === index);

const mixins: Mixins = {};

Expand Down