Skip to content

fix: avoid module preload polyfill for zero js html#4999

Merged
patak-cat merged 2 commits intomainfrom
fix/module-preload-polyfill-with-zero-js
Sep 24, 2021
Merged

fix: avoid module preload polyfill for zero js html#4999
patak-cat merged 2 commits intomainfrom
fix/module-preload-polyfill-with-zero-js

Conversation

@patak-cat
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-cat patak-cat requested a review from antfu September 20, 2021 21:08
@patak-cat patak-cat added the p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) label Sep 20, 2021
@patak-cat patak-cat added this to the 2.6 milestone Sep 20, 2021
@patak-cat
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-cat patak-cat merged commit ac55755 into main Sep 24, 2021
@patak-cat patak-cat 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