-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
fix(scanner): skip svelte components with #snippet
#20562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Detect #snippet in Svelte files and add virtual module export - Externalize virtual-module-named-svelte-dummy modules - Add tests for Svelte snippet handling - Fixes issue #20511 where Svelte snippet exports caused scan failures Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
export * from 'virtual-module-named-svelte-dummy:filename' if the svelte file has #snippet string. externalize modules that starts with virtual-module-named-svelte-dummy-. (削除ここまで)#snippet (追記ここまで)
@copilot update the PR description
@copilot update the PR description
Updated the PR description to match the actual implementation. The main change was correcting virtual-module-named-svelte-dummy to svelte-snippet-dummy to reflect what was actually implemented in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a Vite dependency scanner error that occurs when Svelte files export snippets through their <script module> block. The scanner fails because snippets are defined in the template using {#snippet foo()} syntax, but the scanner only sees the script block where export { foo } references an undeclared identifier.
- Added special handling for Svelte files containing
#snippetsyntax to prevent scanning errors - Introduced a virtual module export mechanism for snippet exports that aren't defined in the script block
- Added an esbuild onResolve handler to externalize
svelte-snippet-dummymodules
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/vite/src/node/optimizer/scan.ts | Adds detection for #snippet syntax and virtual module handling to prevent scanner errors |
| packages/vite/src/node/tests/scan.spec.ts | Adds integration test for Svelte files with snippets and refactors existing test helpers |
| packages/vite/src/node/tests/fixtures/scan-svelte/svelte-snippet.svelte | Test fixture demonstrating a Svelte file with snippet exports |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
/ecosystem-ci run
|
📝 Ran ecosystem CI on
✅ nuxt, astro, ladle, marko, vite-plugin-pwa, quasar, vite-environment-examples, vite-plugin-cloudflare, rakkas, sveltekit, vite-plugin-svelte, unocss, react-router, vitepress, vite-plugin-react, vuepress, vite-setup-catalogue, vike, vitest, vite-plugin-rsc, storybook, waku, vite-plugin-vue |
/ecosystem-ci run
|
📝 Ran ecosystem CI on
✅ ladle, astro, marko, nuxt, unocss, quasar, rakkas, storybook, vike, sveltekit, react-router, vite-plugin-svelte, vite-plugin-react, vite-plugin-vue, vite-plugin-pwa, vitepress, vite-setup-catalogue, vite-environment-examples, vuepress, vite-plugin-cloudflare, vitest, vite-plugin-rsc, waku |
/ecosystem-ci run
|
📝 Ran ecosystem CI on
✅ ladle, marko, one, nuxt, astro, rakkas, vite-plugin-pwa, unocss, vite-plugin-svelte, quasar, vite-plugin-vue, vike, waku, sveltekit, vuepress, vitepress, vite-plugin-react, vite-setup-catalogue |
Uh oh!
There was an error while loading. Please reload this page.
Fixes #20511
When a Svelte file exports snippets through its
<script module>block, Vite's dependency scanner fails with an esbuild error:This happens because snippets are defined in the template using
{#snippet foo()}syntax, but the scanner only sees the script block whereexport { foo }references an undeclared identifier.Solution
This PR adds special handling for Svelte files containing
#snippet:<script module>blocks, check if the file content contains#snippetexport * from 'svelte-snippet-dummy:filename'to handle snippet exports that aren't defined in the script blocksvelte-snippet-dummyExample
Before this fix, this Svelte file would cause scanning to fail:
After the fix, the scanner generates:
The virtual module is externalized, preventing esbuild from trying to resolve snippet exports that don't exist in the script block.
Testing
This change is backward compatible and only affects Svelte files that contain
#snippetsyntax.💬 Share your feedback on Copilot coding agent for the chance to win a 200ドル gift card! Click here to start the survey.