From d6f1ab464947bf7b1c7eadef049b26beb1e6b776 Mon Sep 17 00:00:00 2001 From: Nicolas Hrubec Date: Tue, 25 Aug 2026 13:48:45 +0200 Subject: [PATCH] fix(bundler-plugins): Preserve full file path in component annotation source maps The component annotation Babel transform emitted source maps without `sourceFileName`, so Babel defaulted each map's `sources` to the bare basename, dropping the directory for every annotated .jsx/.tsx file. Pass `sourceFileName` alongside `filename` to keep the full path. Fixes #23561 Co-Authored-By: Ryan Rho <272582209+ryanrho-mercor@users.noreply.github.com> Co-Authored-By: Claude Opus 4.8 (1M context) --- packages/bundler-plugins/src/core/index.ts | 1 + packages/bundler-plugins/test/core/index.test.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/bundler-plugins/src/core/index.ts b/packages/bundler-plugins/src/core/index.ts index a72054a86115..961b6be4d14c 100644 --- a/packages/bundler-plugins/src/core/index.ts +++ b/packages/bundler-plugins/src/core/index.ts @@ -117,6 +117,7 @@ export function createComponentNameAnnotateHooks(ignoredComponents: string[], in const result = await transformAsync(code, { plugins: [[plugin, { ignoredComponents }]], filename: id, + sourceFileName: idWithoutQueryAndHash, parserOpts: { sourceType: 'module', allowAwaitOutsideFunction: true, diff --git a/packages/bundler-plugins/test/core/index.test.ts b/packages/bundler-plugins/test/core/index.test.ts index cc6e6a2eb189..a3362759be60 100644 --- a/packages/bundler-plugins/test/core/index.test.ts +++ b/packages/bundler-plugins/test/core/index.test.ts @@ -1,7 +1,21 @@ -import { getDebugIdSnippet } from '../../src/core'; +import { createComponentNameAnnotateHooks, getDebugIdSnippet } from '../../src/core'; import { containsOnlyImports } from '../../src/core/utils'; import { describe, it, expect } from 'vitest'; +describe('createComponentNameAnnotateHooks', () => { + it.each([ + ['.tsx', '/project/src/shared/providers/AppProviders.tsx'], + ['.jsx', '/project/src/shared/providers/AppProviders.jsx'], + ])('preserves the full file path in the emitted source map (%s)', async (_ext, id) => { + const { transform } = createComponentNameAnnotateHooks([], false); + const code = 'export function AppProviders() {\n return
hello
;\n}\n'; + + const result = await transform(code, id); + + expect(result?.map?.sources).toEqual([id]); + }); +}); + describe('getDebugIdSnippet', () => { it('returns the debugId injection snippet for a passed debugId', () => { const snippet = getDebugIdSnippet('1234');