-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
base: main
Are you sure you want to change the base?
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 <[email protected]>
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 |
Updated the PR description to match the actual implementation. The main change was correcting |
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
#snippet
syntax 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-dummy
modules
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 <[email protected]>
/ecosystem-ci run |
commit: |
📝 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 |
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#snippet
export * from 'svelte-snippet-dummy:filename'
to handle snippet exports that aren't defined in the script blocksvelte-snippet-dummy
Example
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
#snippet
syntax.💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.