Skip to content

Commit 77e55c9

Browse files
committed
Strip Vite query strings from module IDs in RSC plugin
1 parent 6caab9d commit 77e55c9

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/react-router/src/vite/makeAutoInstrumentRSCPlugin.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ export function getServerFunctionWrapperCode(
207207
exportNames: string[],
208208
includeDefault: boolean = false,
209209
): string {
210-
const wrappedId = JSON.stringify(`${originalId}${WRAPPED_MODULE_SUFFIX}`);
210+
// Vite may add query strings (e.g. ?v=abc) to module IDs — strip them so
211+
// the wrapped re-import points at a clean filesystem path.
212+
const cleanId = originalId.split('?')[0] ?? originalId;
213+
const wrappedId = JSON.stringify(`${cleanId}${WRAPPED_MODULE_SUFFIX}`);
211214
const lines = [
212215
"'use server';",
213216
`import { wrapServerFunction } from '${SENTRY_PACKAGE}';`,
@@ -247,7 +250,8 @@ export function makeAutoInstrumentRSCPlugin(options: AutoInstrumentRSCOptions =
247250
if (!id.includes(WRAPPED_MODULE_SUFFIX)) {
248251
return null;
249252
}
250-
const originalPath = id.slice(0, -WRAPPED_MODULE_SUFFIX.length);
253+
const idWithoutSuffix = id.slice(0, -WRAPPED_MODULE_SUFFIX.length);
254+
const originalPath = idWithoutSuffix.split('?')[0] ?? idWithoutSuffix;
251255
try {
252256
return await readFile(originalPath, 'utf-8');
253257
} catch {

packages/react-router/test/vite/makeAutoInstrumentRSCPlugin.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,13 @@ describe('makeAutoInstrumentRSCPlugin', () => {
481481
expect(result).not.toContain('export default');
482482
});
483483

484+
it('strips query strings from the original ID before appending the suffix', () => {
485+
const result = getServerFunctionWrapperCode('/app/routes/actions.ts?v=123', ['myAction']);
486+
487+
expect(result).toContain('/app/routes/actions.ts?sentry-rsc-wrap');
488+
expect(result).not.toContain('?v=123');
489+
});
490+
484491
it('handles file with only default export when includeDefault is true', () => {
485492
const result = getServerFunctionWrapperCode('/app/routes/actions.ts', [], true);
486493

0 commit comments

Comments
 (0)