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

refactor: Ensure module preload polyfill is inlined into main bundle #147

Merged
merged 3 commits into from
Dec 7, 2024

Conversation

rschristian
Copy link
Member

This has been a fairly long-standing issue in the prerenderer that I've unfortunately just not had the time to track down.

The issue is that Rollup/Vite notices both the web entry chunk & the prerender chunk (containing, at a realistic minimum, rts) both depend on a number of shared modules (preact, amongst others) and so it will extract out those shared modules to a separate chunk. This gives us an app entry module like the following:

import '/index.hash123.js';
function modulePreloadPolyfill() { ... }

You can see this if you load up the Preact docs site, the first JS file that's downloaded is just a static import of our actual app & Vite's modulepreload polyfill -- not ideal.

Vite has always added a modulepreload link with the real bundle path, and with this entry being so tiny I wasn't too concerned with the delay it'd cause, but it probably is a wasted ~20+ms on average which is far from optimal.


This PR corrects the behavior, ensuring our bundle & the preload polyfill are merged. This means we have to patch the preload polyfill with a window check too, as the polyfill is an IIFE and the prerender chunk now relies on it, but that should be fine.

@JoviDeCroock JoviDeCroock requested a review from Copilot December 4, 2024 06:52

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no suggestions.

@rschristian rschristian merged commit 4c3f396 into main Dec 7, 2024
1 check passed
@rschristian rschristian deleted the refactor/merge-polyfill-and-bundle branch December 7, 2024 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants