feat(plugin-vue-jsx): inject __file on components in dev/HMR mode#784
Open
NikhilVerma wants to merge 2 commits into
Open
feat(plugin-vue-jsx): inject __file on components in dev/HMR mode#784NikhilVerma wants to merge 2 commits into
__file on components in dev/HMR mode#784NikhilVerma wants to merge 2 commits into
Conversation
`@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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this PR solving?
@vitejs/plugin-vuesets__fileon 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-jsxwas only injecting__hmrId— so JSX and TSX components hadundefinedforinstance.type.__file, making them invisible to devtools open-in-editor functionality.This PR injects
__filealongside__hmrIdwhenever HMR metadata is written, mirroring the behaviour of@vitejs/plugin-vue. The injection is scoped toneedHmr(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
__fileas 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.tswith four unit tests that:__fileis injected on named.jsxand.tsxdefineComponent exports__fileappears alongside__hmrId__fileis not injected in production/build mode