Skip to content

Commit 4bbb2ed

Browse files
nicohrubecryanrho-mercorclaude
authored
fix(bundler-plugins): Preserve full file path in component annotation source maps (#23572)
With `reactComponentAnnotation` enabled, the Babel transform emitted source maps without `sourceFileName`, so Babel defaulted each map's `sources` to the bare basename and every annotated `.jsx`/`.tsx` file lost its directory in the final `.js.map`. Passing `sourceFileName` alongside `filename` restores the full path, matching how non-annotated files and the vite annotation path already behave. Fixes #23561 Co-authored-by: Ryan Rho <272582209+ryanrho-mercor@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 936541e commit 4bbb2ed

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

packages/bundler-plugins/src/core/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export function createComponentNameAnnotateHooks(ignoredComponents: string[], in
117117
const result = await transformAsync(code, {
118118
plugins: [[plugin, { ignoredComponents }]],
119119
filename: id,
120+
sourceFileName: idWithoutQueryAndHash,
120121
parserOpts: {
121122
sourceType: 'module',
122123
allowAwaitOutsideFunction: true,

packages/bundler-plugins/test/core/index.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
import { getDebugIdSnippet } from '../../src/core';
1+
import { createComponentNameAnnotateHooks, getDebugIdSnippet } from '../../src/core';
22
import { containsOnlyImports } from '../../src/core/utils';
33
import { describe, it, expect } from 'vitest';
44

5+
describe('createComponentNameAnnotateHooks', () => {
6+
it.each([
7+
['.tsx', '/project/src/shared/providers/AppProviders.tsx'],
8+
['.jsx', '/project/src/shared/providers/AppProviders.jsx'],
9+
])('preserves the full file path in the emitted source map (%s)', async (_ext, id) => {
10+
const { transform } = createComponentNameAnnotateHooks([], false);
11+
const code = 'export function AppProviders() {\n return <div>hello</div>;\n}\n';
12+
13+
const result = await transform(code, id);
14+
15+
expect(result?.map?.sources).toEqual([id]);
16+
});
17+
});
18+
519
describe('getDebugIdSnippet', () => {
620
it('returns the debugId injection snippet for a passed debugId', () => {
721
const snippet = getDebugIdSnippet('1234');

0 commit comments

Comments
 (0)