From 4333dba60ddaf5fd3a17a8d4b44023a2871bf3af Mon Sep 17 00:00:00 2001 From: Nicolas Hrubec Date: Tue, 25 Aug 2026 17:06:57 +0200 Subject: [PATCH] fix(v10/bundler-plugins): Preserve full file path in component annotation source maps Backport of: #23572 --- 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');