-
-
Notifications
You must be signed in to change notification settings - Fork 389
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
HMR: inferring script source from moduleId is not reliable and don't work with [hash]
/[fullhash]
#444
Comments
We recommend disable |
And maybe won't fix |
Also please provide minimum reproducible test cases (some of them can be fixed like |
That still leaves two of three bugs: async loading and Could you shed some light on why the "last |
Maybe it is bug, sometimes bugs happen, you can send a PR with fixes |
Pinging @ScriptedAlchemy who seems to be the original author of the HMR code and might know the rationale for the "last |
@jsnajdr anyway if you provide reproducible examples it help to use fix problem faster |
Last time I did that in #253, after a very similar conversation, it didn't help. I'd be very happy to spend my time creating and testing a patch though. Are there any suggestions on how to figure out the chunk IDs from module ID inside the webpack runtime? That would help implement the hot reloading reliably. |
Can you expand on that? The HMR code already knows the module ID. It needs to figure out the chunk URLs to reload. |
No information about chunk |
Tests are failing
It is possible to collect moduleId => chunkIds map at compile time, pass it to runtime chunk and use from HMR. |
Other example:
|
Also need test with |
[hash]
/[fullhash]
Does this means |
I reproduce the problem in Webpack5 with |
…(MiniCssExtractPlugin dont work hmr if css bundle-name contains [hash] webpack-contrib/mini-css-extract-plugin#444
The HMR code needs to do some magic to convert the
moduleId
of the updated module to the URLs of the CSS chunks that contain the module. These URLs then need to be reloaded.Trying to enable it in Calypso revealed at least three bugs:
Doesn't work with async-loaded chunks
getCurrentScriptUrl
relies ondocument.currentScript
, which works when the chunk is loaded withscript
tag, but not when a chunk is loaded asynchronously. Then the module is evaluated in aPromise.then
handler anddocument.currentScript
isnull
. No hot reload.Is not reliable with shared chunks
With shared async chunks optimized by
SplitChunksPlugin
, it commonly happens that a module code is duplicated in multiple chunks. To reliably hot-reload their CSS, we need to reload all the CSS chunks where the module is bundled. That doesn't happen at this moment. Only the chunk that was used to actually execute the module is reloaded.Fallback to "last
script
tag" almost never worksWhen
getCurrentScriptUrl
can't finddocument.currentScript
, it falls back to using thesrc
attribute of the lastscript
tag in the document. That works for very simple apps that load a single JS bundle, but fails in cases like:moduleId
script
tag is not owned by webpack, but loads something else. For example, analytics from a 3rd party sourcescript
doesn't have asrc
attribute, but is an inline script. Then the HMR code will crash withTypeError: Cannot read property 'some' of null
The text was updated successfully, but these errors were encountered: