Skip to content
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

fix(build): handle preload treeshaking for braces #17479

Merged
merged 1 commit into from
Jun 14, 2024
Merged

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Jun 14, 2024

Description

fix #17478

Handle the cases shown in the issue above. The third part of the regex was to lax to support import(...).then(function ({ ... }) so I tighten it up so it's not too greedy.


While fixing this, I started to notice that regexes would fall apart as long as someone sets fallback values, like:

const { foo = "fallback" } = await import(...)

await import(...).then(({ foo = "fallback" }) => {})

The "fallback" could be anything that tricks the regex to end early. However, I think it's very rare for dynamic imports to have fallback values, so we can see how far regex goes before needing to go with an AST approach. Or maybe until then we can rethink preload transforms.

@bluwy bluwy added the p4-important Violate documented behavior or significantly improves performance (priority) label Jun 14, 2024
Copy link

stackblitz bot commented Jun 14, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@bluwy
Copy link
Member Author

bluwy commented Jun 14, 2024

/ecosystem-ci run

Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge the fix. Maybe we should bailout of the optimization if we detect a fallback?

@patak-dev patak-dev enabled auto-merge (squash) June 14, 2024 08:54
@bluwy
Copy link
Member Author

bluwy commented Jun 14, 2024

Now that you mention it, it's actually not that hard to bail out, by checking if the matched part as a = 🤔

@patak-dev patak-dev merged commit d355568 into main Jun 14, 2024
11 checks passed
@patak-dev patak-dev deleted the fix-preload-braces branch June 14, 2024 08:57
@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on dd93fd0: Open

suite result latest scheduled
nuxt failure failure
sveltekit failure success
vite-plugin-react-pages failure failure
vitest failure failure

analogjs, astro, histoire, ladle, laravel, marko, previewjs, quasar, qwik, rakkas, remix, unocss, vike, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-svelte, vite-plugin-vue, vite-setup-catalogue, vitepress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4-important Violate documented behavior or significantly improves performance (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic import syntax errors in 5.3
2 participants