Skip to content

feat(plugin-vue-jsx): inject __file on components in dev/HMR mode#784

Open
NikhilVerma wants to merge 2 commits into
vitejs:mainfrom
NikhilVerma:feat/inject-file-property-jsx-tsx
Open

feat(plugin-vue-jsx): inject __file on components in dev/HMR mode#784
NikhilVerma wants to merge 2 commits into
vitejs:mainfrom
NikhilVerma:feat/inject-file-property-jsx-tsx

Conversation

@NikhilVerma
Copy link
Copy Markdown

What is this PR solving?

@vitejs/plugin-vue sets __file on every SFC component in dev mode, enabling Vue DevTools' component inspector and open-in-editor to identify the component's source file. @vitejs/plugin-vue-jsx was only injecting __hmrId — so JSX and TSX components had undefined for instance.type.__file, making them invisible to devtools open-in-editor functionality.

This PR injects __file alongside __hmrId whenever HMR metadata is written, mirroring the behaviour of @vitejs/plugin-vue. The injection is scoped to needHmr (i.e. dev/serve mode only), so production builds are unaffected.

Fixes #783

What other alternatives were considered?

A post-transform regex approach can inject __file as a Vite plugin downstream (e.g. in @vue/devtools-vite), but it is fragile and shouldn't be the responsibility of downstream tooling. The root cause is that the plugin itself never emits __file, so the fix belongs here.

Tests

Added packages/plugin-vue-jsx/__tests__/file-injection.spec.ts with four unit tests that:

  • Verify __file is injected on named .jsx and .tsx defineComponent exports
  • Verify __file appears alongside __hmrId
  • Verify __file is not injected in production/build mode

NikhilVerma and others added 2 commits May 18, 2026 08:09
`@vitejs/plugin-vue` sets `__file` on every SFC component in dev mode,
enabling Vue DevTools' component inspector and open-in-editor to resolve
source files. `plugin-vue-jsx` was only injecting `__hmrId` — so JSX/TSX
components were invisible to devtools file-open features.

Inject `__file` alongside `__hmrId` whenever HMR metadata is written,
mirroring the SFC plugin's behavior. Scoped to `needHmr` (dev/serve mode)
so production builds are unaffected.

Fixes: vitejs#783

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Expand unit tests to cover all export shapes: named, named-via-specifier,
  default, and default-with-type-assertion; plus negative cases for build,
  SSR, and .vue script blocks.
- Expose Named/Default/TsxDefault.__file via window globals in the vue-jsx
  playground and add corresponding e2e assertions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugin-vue-jsx: __file not injected on JSX/TSX components, breaking Vue DevTools 'Open in Editor'

1 participant