-
Notifications
You must be signed in to change notification settings - Fork 801
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
Hot ejected CRA not working (followed recipe and generic setup) #1440
Comments
And how it is not working? |
I worked on it a bit more and realized the hot reloading works for the App component itself, but not for pages rendered by it. Yesterday I thought nothing worked (since I was changing code in one of the pages to test). Is this expected behaviour? I lazy import my app and all pages. My App is rendered as such, where Router renders a Switch with all routes. App is hot exported.
|
It depends on how you lazy load. If you use |
I use react.lazy with a retry function
|
🤷♂️should work. Please provide source code for |
I just tried changing it to I tried wrapping my page's export in hot, and hot reloading works just fine then. Could the problem of hot not being propagated down from App to pages be related to the way/order I render App and Routes? index.js
Router is being passed down as children and App is lazy imported after Router. In App I instanciate hot from 'react-hot-loader/root' for the first time. Should that make a difference or do you have other ideas? Thanks so much for the help so far by the way @theKashey edit: |
Dam, I was going to say that you have to wrap |
I'll try some other tweaks when Router is wrapped later today, might get it to work. Otherwise I guess I'll just have wrap each page component - a bit tedious but gets the job done. |
Have fun 😅. Sometimes this is the only advice I could provide. |
@theKashey do you think it is problematic to store routes in an array where each route object looks like below?
it is then mapped out in Router as below
|
Testing more and it seems that components directly rendered by App (which is wrapped in hot) don't hot reload. Hot reloading app itself works, however. Also, when wrapping a component that isn't App (e.g. a page) with hot, the child-components hot reload correctly. Could it be that I need to change from import on */root to the index file? Or that I should use hot(module) instead of just hot()? Edit:
|
I've also tried wrapping my routes (when I map them out in my Switch) in my own HotProvider.
HotProvider.js:
Doesn't work either, I need to wrap each page file where it's exported it seems. |
I think if const searchPage = reactUtils.lazyWithRetry(() => import('../pages/SearchPage')) |
Tried it now and it doesn't seem to work. (Unless I misunderstood). See below.
TopLevelPage export:
|
Another question if you have the time, what about looking at fast refresh? Seems to be some experimental support even though the README says to use react-hot-loader: |
React-Hot-Loader and fast refresh are roughly the same things nowadays, except the module update handling - fast refresh(actually a webpack plugin, which is not a part of fast refresh) is going to catch the update on the module boundary, not on the custom placed Problem with lazy is simple - something has to execute However, I've just remembered one thing which might help you -
I shall fix your problem removing some automagic, and making lazy update a bit more explicit. |
Probably related to #1425 |
I managed to get it to work. The problem was that my routes were (lazy) imported in another file (than my router), e.g: old Router.js:
new Router.js:
Top level exports or not (in routes.js) did not make a difference. @theKashey thanks a lot, your tips were of great help when debugging |
Description
I have a project based on CRA which is ejected. Hot-reloading reducers and sagas works perfectly fine (with standard if(module.hot) module.hot.accept(...) snippets). However, I cannot seem to get hot reloading of the react App to work. I've tried both accepting changes on App.js and also implementing RHL according to the README.
Expected behavior
I expect the hot reloading to catch changes when I modify the code.
Actual behavior
Nothing is triggered, and the page reloads as if no hot reloading was implemented.
Environment
From package.json:
(- "react-dom": "16.8.4", removed)
Node version: v10.0.0
Npm version: 5.6.0
Operating system: macOS
Browser: Chrome 80.0.3987.163 (Official Build) (64-bit)
Relevant code/settings:
These are the only changes I've made to the default CRA settings:
App.js
webpack.config.dev.js
Any ideas om what could be wrong with my setup?
The text was updated successfully, but these errors were encountered: