Skip to content
Closed
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
12 changes: 6 additions & 6 deletions packages/nextjs/src/index.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { addIntegration, UserIntegrations } from './utils/userIntegrations';
export * from '@sentry/react';
export { nextRouterInstrumentation } from './performance/client';

const { BrowserTracing } = TracingIntegrations;
const { BrowserTracing } = TracingIntegrations || {};
export const Integrations = { ...BrowserIntegrations, BrowserTracing };
Comment on lines +12 to 13
Copy link
Copy Markdown
Member

@lobsterkatie lobsterkatie Sep 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like us to handle this better in the future, but for now, please just add this TODO and edit to the export const Integrations line.

Suggested change
const { BrowserTracing } = TracingIntegrations || {};
export const Integrations = { ...BrowserIntegrations, BrowserTracing };
// TODO: The `|| {}` here is a workaround to enable people not using tracing to reduce bundle size by using
// `resolve.alias["@sentry/tracing"] = false` in their webpack config to tell webpack 5+ to replace the tracing package
// with an empty object. If they do that , `TracingIntegrations` will be undefined and this destructuring will fail
// without the empty object being provided as an alternative from which to unpack. In the long run, we should handle
// this internally.
const { BrowserTracing } = TracingIntegrations || {};
export const Integrations = { ...BrowserIntegrations, ...(BrowserTracing && {BrowserTracing}) };


/** Inits the Sentry NextJS SDK on the browser with the React SDK. */
Expand All @@ -33,12 +33,12 @@ export function init(options: NextjsOptions): void {
});
}

const defaultBrowserTracingIntegration = new BrowserTracing({
tracingOrigins: [...defaultRequestInstrumentationOptions.tracingOrigins, /^(api\/)/],
routingInstrumentation: nextRouterInstrumentation,
});

function createClientIntegrations(integrations?: UserIntegrations): UserIntegrations {
const defaultBrowserTracingIntegration = new BrowserTracing({
tracingOrigins: [...defaultRequestInstrumentationOptions.tracingOrigins, /^(api\/)/],
routingInstrumentation: nextRouterInstrumentation,
});

if (integrations) {
return addIntegration(defaultBrowserTracingIntegration, integrations, {
BrowserTracing: { keyPath: 'options.routingInstrumentation', value: nextRouterInstrumentation },
Expand Down