-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Bundle requests twice in Firefox 93 with default polyfillModulePreload enabled #5532
Comments
The same here. It looks like this polyfill doesn't work in Firefox. |
It's wrong, see below. |
Okay, I have made minimal reproducible example of polyfill used in vite and confirm that it makes two requests by design. First, dummy, request makes polyfill with
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="modulepreload" href="module.mjs">
</head>
<body>
Hello
<script>
function processPreload(link) {
const fetchOpts = {};
if (link.integrity)
fetchOpts.integrity = link.integrity;
if (link.referrerpolicy)
fetchOpts.referrerPolicy = link.referrerpolicy;
if (link.crossorigin === 'use-credentials')
fetchOpts.credentials = 'include';
else if (link.crossorigin === 'anonymous')
fetchOpts.credentials = 'omit';
else
fetchOpts.credentials = 'same-origin';
fetch(link.href, fetchOpts).then(res => res.ok && res.arrayBuffer());
}
for (const link of document.querySelectorAll('link[rel=modulepreload]')) {
processPreload(link);
}
</script>
<script type="module">
import { test } from './module.mjs';
test('yay');
</script>
</body>
</html>
export function test(message) {
alert(message)
}
I think it's can't be fixed. Any suggestions? |
Can confirm this issue also occurs on Firefox 95.0.2. It's a simple React project using Vite and Firefox is downloading all non index.js assets twice. |
So what is the workaround for that? Edit: actually if I turn off
Notice how module has dependency on itself. That's why it would load twice, first by doing dependency loading and then by doing browser |
I've just noticed this myself, and although it is not causing any measurable harm in my case, it is really messing with me. Vite version 2.8.4, Firefox 97.0.1. I'm using Vue, and the vendor js file is downloaded twice. |
Same for me, vendor.js is loaded twice and that bothers me a lot! |
I think this is because vite/packages/vite/src/node/preview.ts Line 93 in 9a93233
If there is no Cache-Control header, browser needs to revalidate the response.
|
It seems that Vite is trying to be smart with this option. It’s a recommended optimization technique, so the JS chunks and their dependencies are loaded in parallel, instead of in waterfall. First, they download ( The fact that we see these duplicated requests happening on Safari and Firefox is because it relies on (a polyfill of) a feature that is only available in Chromium browsers. More info: https://developer.chrome.com/blog/modulepreload/ I wouldn’t worry about non-Chromium browsers for now, since the second request is always returned from cache. I think it’s a good default we can have for now. Even if it is bothering to see in the Network tab. |
That doesn't always happen sadly, if the first request hasn't finished before the second one started then the second one is not returned from cache |
On the latest Firefox (macOS) I do see the data transferred twice, so, as @kito-inv mentioned above, it's not cached.
According to the caniuse data, ~25% of the userbase may be affected. Personally, it's not really a percentage I am comfortable with on a production server for a default behavior. |
Chiming in to say I see the same issue on Firefox 109.0 for Mac OS 👎 Same issue with Safari, but not in Chrome. Could we get confirmation on what the recommended course of action here is? If we disable the preload polyfill option as described above by the original poster, is that going to cause issues elsewhere? If so, what? Edit: Found my way to #9938 and followed instructions there to disable this feature. I believe this issue should be closed and pointed to that PR. |
Same issue. I've tried disabling optimizeDeps and modulePreload. Still happening. I'm fully capable of parallelizing/preloading my own promises, thanks 🙄. This isn't something that it should be generating code for and trying to do automatically. |
I am having the same behavior, no matter if modulePreload is polyfilled or not. It looks like this is not an issue from Vite, but a behavior (bug?) from Firefox. When doing a dynamic import ( So either this is a bug in Firefox, or it will be repaired as soon as Firefox starts supporting But if you modifiy the generated I also tested to change the |
I would like to be able to disable the preload feature completly by setting |
It's not a Firefox fault, as I stated in my comment there is a clear reason why this is not working properly. |
Bumping this as it is still unresolved for Firefox. |
I have exactly the same behavior for Chrome with vite 4.4.8, but only in |
notice that this is not only about network traffic, I am migrating a project to vite and there a canvas is added to the body in a index.ts script, I noticed that 2 canvas were added to the body and was scratching my head until I realized it was vite loading the same script twice |
Hey folks, I just switched from webpack to vite (using vite for react in laravel 6) and encountered the same thing and found a solution. Files that are dynamically imported will be called twice. I don't know if your case is the same as mine, but I noticed that the Request URL of the two calls is not the same: My public folder structure looks like this: And a similar problem with the CSS file of that chunk file, it is only loaded once like the 1st of the chunk file: And I added 'base' config like this:
After:
Dynamic chunks are now only loaded once and CSS is also loaded correctly. Hope it will be useful to someone. |
Fixed in Firefox 115: https://caniuse.com/link-rel-modulepreload |
Describe the bug
I have found that default vite build makes bundle request twice in firefox.
When I switch off
build.polyfillModulePreload: false
it makes only one request. Why this happens? Vite docs says that polyfill need for firefox and safari, Can I Use says that modulepreload not supported in Firefox. Is this proper polyfill work?There is no problem in Chrome or Safari
Reproduction
Open http://127.0.0.1:5000/ in Firefox 93.0 (64-bit)
Check dev tools F12 -> Network ->Reload
System Info
Used Package Manager
pnpm
Logs
Validations
The text was updated successfully, but these errors were encountered: