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(hoisted scripts): consider script's dependents #7144

Merged
merged 1 commit into from May 22, 2023

Conversation

lilnasy
Copy link
Contributor

@lilnasy lilnasy commented May 19, 2023

Changes

Fixes #7116
The hoisted scripts plugin seems to have been written with the assumption that each chunk is more-or-less an independent chunk of code. This assumption breaks as Vite creates shared chunks when multiple pages use the same scripts. We already consider that a script may import other scripts, but not that it may be imported by others. This leads to a case where we inline a hoisted script and delete it from the bundle while other scripts have a reference to it.

Testing

The bug only manifests in large websites where Vite can deduplicate hoisted scripts by creating shared chunks from them. Not sure how to go about making a fixture for this.

Docs

Not affected.

@changeset-bot
Copy link

changeset-bot bot commented May 19, 2023

🦋 Changeset detected

Latest commit: 73487e7

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label May 19, 2023
@matthewp matthewp merged commit ba06362 into withastro:main May 22, 2023
13 checks passed
@astrobot-houston astrobot-houston mentioned this pull request May 22, 2023
@lilnasy lilnasy deleted the hoisted-script-fix branch May 22, 2023 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with vitePluginAnalyzer
2 participants