HMR is broken with non-universal import()
See original GitHub issueHello there,
I’m not 100% sure that my issue is related to the babel plugin or RUC.
I created the following repository (React SSR app) to demonstrate the issue when executing an import() which is not handled by RUC (ie. as an universal component), that is breaking HMR. I use this import to polyfill the client if required.
Steps to reproduce the issue
- git clone https://github.com/cdoublev/react-ssr-debug-hmr
npm start
and open your browser- Open src/universal/hello.js in your editor and change the text: no hot update
- Open src/index.js in your editor and remove/comment L#5
- Change the text of src/universal/hello.js again: hot update
I spend about 3 hours on this issue but I didn’t look at the sources of this plugin, and it’s been a long time since I read the posts from faceyspacey, explaining what it does and how chunks ids are saved and shared between server and client.
I will try to look deeper soon, but as I can easily remove this import() in dev mode, I will first continue the work I was on. But any advice/comments would be appreciated.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13
Top GitHub Comments
Can you make a PR?
Hello again,
The following change in
babel-plugin-universal-import/index.js
fixes this HMR issue.It prevents transforming this:
into this:
The latter will make
src/notUniversalModule.js
amodule.parents
ofbabel-plugin-universal-import/universalImport.js
, which is not wanted, and prevents hot reload of all modules (even the modules wrapped withuniversal
) with anunaccepted update
.Adding a unit test would involve updating all tests by adding
import universal from 'react-universal-component
. Also note that traversing the tree upwards for each import statement will obviously have a performance impact.As a reminder, the goal of a dynamic import only client side, not handled by this plugin, is for example loading a polyfill. Its “universal” loading isn’t required as it will not change the HTML, and its dynamic loading before running the application (hydration) IS a requirement.
Waiting for your comments.
EDIT: the user could rename the default export of
react-universal-component
to something else thanuniversal
, therefore my suggested fix should handle this (sorry!).