Skip to content

Commit fe86f1a

Browse files
chargomeclaude
andcommitted
feat(react-router)!: Remove unstable_sentryVitePluginOptions
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 3601edd commit fe86f1a

7 files changed

Lines changed: 79 additions & 502 deletions

File tree

‎dev-packages/e2e-tests/test-applications/react-router-sourcemaps/vite.config.ts‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@ import { reactRouter } from '@react-router/dev/vite';
22
import { sentryReactRouter, type SentryReactRouterBuildOptions } from '@sentry/react-router';
33
import { defineConfig } from 'vite';
44

5-
// Deliberately routes `sourcemaps` through `unstable_sentryVitePluginOptions`. That shape
6-
// used to drop the SDK's `sourcemaps.disable: true`, which re-enabled debug ID injection in
7-
// the Vite plugin on top of the injection done by `sentryOnBuildEnd` - two debug IDs per
8-
// chunk, only one of which has an uploaded artifact bundle.
9-
// See https://github.com/getsentry/sentry-javascript/issues/22929
5+
// Guards against debug IDs being injected twice - once by the Vite plugin and once by
6+
// `sentryOnBuildEnd` - which leaves two IDs per chunk, only one of which has an uploaded
7+
// artifact bundle. See https://github.com/getsentry/sentry-javascript/issues/22929
108
export const sentryConfig: SentryReactRouterBuildOptions = {
119
authToken: 'fake-auth-token',
1210
org: 'test-org',
1311
project: 'test-project',
12+
sentryUrl: 'http://localhost:3032',
1413
release: {
1514
name: 'test-release',
1615
},
17-
unstable_sentryVitePluginOptions: {
18-
url: 'http://localhost:3032',
19-
sourcemaps: {
20-
// The maps have to survive until `sentryOnBuildEnd` uploads them, so this asserts
21-
// the option is not forwarded to the Vite plugin (which deletes in a `finally`).
22-
filesToDeleteAfterUpload: ['./build/client/assets/**/*.map'],
23-
},
16+
sourcemaps: {
17+
// The maps have to survive until `sentryOnBuildEnd` uploads them, so this asserts the option is
18+
// not forwarded to the Vite plugin (which deletes in a `finally` block regardless of `disable`).
19+
filesToDeleteAfterUpload: ['./build/client/assets/**/*.map'],
2420
},
2521
debug: true,
2622
};

‎packages/react-router/src/vite/buildEnd/handleOnBuildEnd.ts‎

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ function getSentryConfig(viteConfig: unknown): SentryReactRouterBuildOptions {
1616
return (viteConfig as { sentryConfig: SentryReactRouterBuildOptions }).sentryConfig;
1717
}
1818

19-
/**
20-
* This hook is the only place that injects debug IDs and uploads source maps for React
21-
* Router, so `disable` has to be honoured wherever the user set it. Reading it from the
22-
* top-level config only would silently ignore `unstable_sentryVitePluginOptions`.
23-
*/
24-
function resolveSourceMapsDisable(sentryConfig: SentryReactRouterBuildOptions): boolean | 'disable-upload' | undefined {
25-
return sentryConfig.sourcemaps?.disable ?? sentryConfig.unstable_sentryVitePluginOptions?.sourcemaps?.disable;
26-
}
27-
2819
/**
2920
* A build end hook that handles Sentry release creation and source map uploads.
3021
* It creates a new Sentry release if configured, uploads source maps to Sentry,
@@ -33,42 +24,36 @@ function resolveSourceMapsDisable(sentryConfig: SentryReactRouterBuildOptions):
3324
export const sentryOnBuildEnd: BuildEndHook = async ({ reactRouterConfig, viteConfig }) => {
3425
const sentryConfig = getSentryConfig(viteConfig);
3526

36-
const unstableSentryVitePluginOptions = sentryConfig.unstable_sentryVitePluginOptions;
37-
3827
const {
3928
authToken,
29+
headers,
4030
org,
4131
project,
4232
release,
33+
sentryUrl,
4334
sourcemaps = { disable: false },
4435
debug = false,
4536
}: Omit<SentryReactRouterBuildOptions, 'sourcemaps'> &
4637
// Pick 'sourcemaps' from Vite plugin options as the types allow more (e.g. Promise values for `deleteFilesAfterUpload`)
4738
Pick<SentryVitePluginOptions, 'sourcemaps'> = {
48-
...unstableSentryVitePluginOptions,
4939
...sentryConfig,
5040
sourcemaps: {
51-
...unstableSentryVitePluginOptions?.sourcemaps,
5241
...sentryConfig.sourcemaps,
53-
disable: resolveSourceMapsDisable(sentryConfig),
42+
disable: sentryConfig.sourcemaps?.disable,
5443
},
5544
release: {
56-
...unstableSentryVitePluginOptions?.release,
5745
...sentryConfig.release,
5846
},
59-
project: unstableSentryVitePluginOptions?.project
60-
? Array.isArray(unstableSentryVitePluginOptions?.project)
61-
? unstableSentryVitePluginOptions?.project[0]
62-
: unstableSentryVitePluginOptions?.project
63-
: sentryConfig.project,
6447
};
6548

49+
// `url` and `headers` previously only reached the CLI through `unstable_sentryVitePluginOptions`,
50+
// so self-hosted setups had no supported way to point this upload at their instance.
6651
const cliInstance = new SentryCli(null, {
6752
authToken,
53+
headers,
6854
org,
69-
...sentryConfig.unstable_sentryVitePluginOptions,
70-
// same handling as in bundler plugins: https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/05084f214c763a05137d863ff5a05ef38254f68d/packages/bundler-plugin-core/src/build-plugin-manager.ts#L102-L103
71-
project: Array.isArray(project) ? project[0] : project,
55+
project,
56+
url: sentryUrl,
7257
});
7358

7459
// check if release should be created

‎packages/react-router/src/vite/makeCustomSentryVitePlugins.ts‎

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,50 @@
11
import { sentryVitePlugin } from '@sentry/bundler-plugins/vite';
2+
import { warnOnRemovedBuildOptions } from '@sentry/core';
23
import { type Plugin } from 'vite';
34
import type { SentryReactRouterBuildOptions } from './types';
45

56
/**
67
* Create a custom subset of sentry's vite plugins
78
*/
89
export async function makeCustomSentryVitePlugins(options: SentryReactRouterBuildOptions): Promise<Plugin[]> {
10+
warnOnRemovedBuildOptions(options, ['unstable_sentryVitePluginOptions']);
11+
912
const {
1013
debug,
11-
unstable_sentryVitePluginOptions,
1214
bundleSizeOptimizations,
1315
applicationKey,
1416
authToken,
17+
moduleMetadata,
1518
org,
1619
project,
1720
telemetry,
1821
reactComponentAnnotation,
1922
release,
2023
} = options;
2124

22-
const unstableSourcemapsDisable = unstable_sentryVitePluginOptions?.sourcemaps?.disable;
23-
24-
// Anything other than `true` would have the Vite plugin inject debug IDs on top of the
25-
// ones `sentryOnBuildEnd` injects, which breaks source map resolution. The value still
26-
// applies to the buildEnd hook - only the Vite plugin ignores it.
27-
if (unstableSourcemapsDisable !== undefined && unstableSourcemapsDisable !== true) {
28-
// eslint-disable-next-line no-console
29-
console.warn(
30-
`[Sentry] \`unstable_sentryVitePluginOptions.sourcemaps.disable: ${JSON.stringify(
31-
unstableSourcemapsDisable,
32-
)}\` does not apply to the Vite plugin. Debug ID injection and source map upload are handled by the \`sentryOnBuildEnd\` hook for React Router, so letting the Vite plugin do it as well would inject a second debug ID per chunk. The option still applies to \`sentryOnBuildEnd\`.`,
33-
);
34-
}
35-
3625
const sentryVitePlugins = sentryVitePlugin({
3726
applicationKey,
3827
authToken: authToken ?? process.env.SENTRY_AUTH_TOKEN,
3928
bundleSizeOptimizations,
4029
debug: debug ?? false,
30+
moduleMetadata,
4131
org: org ?? process.env.SENTRY_ORG,
4232
project: project ?? process.env.SENTRY_PROJECT,
33+
reactComponentAnnotation,
34+
release,
4335
telemetry: telemetry ?? true,
44-
// Spread here so it can override the plain options above, but not the objects
45-
// merged below - object spread replaces whole keys rather than deep-merging.
46-
...unstable_sentryVitePluginOptions,
4736
_metaOptions: {
48-
...unstable_sentryVitePluginOptions?._metaOptions,
4937
telemetry: {
50-
...unstable_sentryVitePluginOptions?._metaOptions?.telemetry,
5138
metaFramework: 'react-router',
5239
},
5340
},
54-
reactComponentAnnotation: {
55-
// Only assign when set, as an explicit `undefined` would erase the unstable value
56-
...(reactComponentAnnotation?.enabled !== undefined && { enabled: reactComponentAnnotation.enabled }),
57-
...(reactComponentAnnotation?.ignoredComponents !== undefined && {
58-
ignoredComponents: reactComponentAnnotation.ignoredComponents,
59-
}),
60-
...unstable_sentryVitePluginOptions?.reactComponentAnnotation,
61-
},
62-
release: {
63-
...unstable_sentryVitePluginOptions?.release,
64-
...release,
65-
},
6641
sourcemaps: {
67-
...unstable_sentryVitePluginOptions?.sourcemaps,
68-
// Injection and upload are handled in the buildEnd hook, so the Vite plugin must
69-
// never do it too. This is deliberately not overridable - see the warning above.
42+
// Debug ID injection and upload are handled by the `sentryOnBuildEnd` hook, so the Vite plugin
43+
// must never do it as well - that would inject a second debug ID per chunk and break source
44+
// map resolution.
7045
disable: true,
71-
// The plugin deletes these in a `finally` block that runs regardless of `disable`,
72-
// which would remove the maps before `sentryOnBuildEnd` gets to upload them.
73-
// Deletion is handled there instead, from the same option.
46+
// The plugin deletes these in a `finally` block that runs regardless of `disable`, which would
47+
// remove the maps before `sentryOnBuildEnd` gets to upload them. Deletion happens there instead.
7448
filesToDeleteAfterUpload: undefined,
7549
},
7650
}) as Plugin[];
Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
import type { BuildTimeOptionsBase, UnstableVitePluginOptions } from '@sentry/core';
2-
import type { SentryVitePluginOptions } from '@sentry/bundler-plugins/vite';
1+
import type { BuildTimeOptionsBase, ReactComponentAnnotationOptions } from '@sentry/core';
32

4-
export type SentryReactRouterBuildOptions = BuildTimeOptionsBase &
5-
UnstableVitePluginOptions<Partial<SentryVitePluginOptions>> & {
6-
/**
7-
* Options related to react component name annotations.
8-
* Disabled by default, unless a value is set for this option.
9-
* When enabled, your app's DOM will automatically be annotated during build-time with their respective component names.
10-
* This will unlock the capability to search for Replays in Sentry by component name, as well as see component names in breadcrumbs and performance monitoring.
11-
* Please note that this feature is not currently supported by the esbuild bundler plugins, and will only annotate React components
12-
*/
13-
reactComponentAnnotation?: {
14-
/**
15-
* Whether the component name annotate plugin should be enabled or not.
16-
*/
17-
enabled?: boolean;
18-
19-
/**
20-
* A list of strings representing the names of components to ignore. The plugin will not apply `data-sentry` annotations on the DOM element for these components.
21-
*/
22-
ignoredComponents?: string[];
23-
};
24-
};
3+
export type SentryReactRouterBuildOptions = BuildTimeOptionsBase & {
4+
/**
5+
* Options related to react component name annotations.
6+
* Disabled by default, unless a value is set for this option.
7+
* When enabled, your app's DOM will automatically be annotated during build-time with their respective component names.
8+
* This will unlock the capability to search for Replays in Sentry by component name, as well as see component names in breadcrumbs and performance monitoring.
9+
* Please note that this feature is not currently supported by the esbuild bundler plugins, and will only annotate React components
10+
*/
11+
reactComponentAnnotation?: ReactComponentAnnotationOptions;
12+
};

0 commit comments

Comments
 (0)