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: avoid module preload polyfill for zero js html #4999

Merged
merged 2 commits into from Sep 24, 2021

Conversation

patak-dev
Copy link
Member

Description

After #4555, we closed #3127 but @DylanPiercey found out that the module preload polyfill is still loaded when there isn't any JS.

This PR adds a guard avoiding adding the polyfill in html entries that don't have any script module (for example, a simple 404 page).
The user may add modules in pre plugins, but these are executed before the guard. If the user adds a module in a post plugin, they are executed after the preloads are inserted so these tags will still not need the polyfill internally.

The only case would be if the user is adding a tag + preload by hand in a post plugin, but I can't see why someone would want to avoid these scripts be processed by Vite. In the worst case scenario, this will only mean a that some browsers will not take into account that preload. We could document this gotcha if someone thinks this is something users will end up hitting.

Additional context

An alternative is to always add the polyfill and remove it when analyzing the generated chunk. I tried to do so and it isn't straightforward. And the same caveat would apply here, the user may still add something by hand as a post plugin transforming the html.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@patak-dev patak-dev added the p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) label Sep 20, 2021
@patak-dev patak-dev added this to the 2.6 milestone Sep 20, 2021
@patak-dev
Copy link
Member Author

The only case would be if the user is adding a tag + preload by hand in a post plugin, but I can't see why someone would want to avoid these scripts be processed by Vite. In the worst case scenario, this will only mean a that some browsers will not take into account that preload. We could document this gotcha if someone thinks this is something users will end up hitting.

We discussed this with the team today, and we shouldn't need to worry about this edge case

@patak-dev patak-dev merged commit ac55755 into main Sep 24, 2021
@patak-dev patak-dev deleted the fix/module-preload-polyfill-with-zero-js branch September 24, 2021 14:10
aleclarson pushed a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Zero JS™ output in build mode.
2 participants