Skip to content

React.lazy is not working with react-hot-loader #1139

@ffan0811

Description

@ffan0811

Description

I'm trying to use lazy and suspense from react with react-hot-loader.
react-hot-loader works fine without lazy feature and visa versa. However, If I use the lazy feature with react-hot-loader, the component doesn't render immediately.
the flow is like

  1. There's an element <p>this is test</p> and I edited it to <p>this is testt</p> in component A and saved the file.
  2. I can see the logs from HMR. ([HMR] App is up to date.) but the view is still showing "this is test".
  3. I edited the element to <p>this is testt!</p> from <p>this is testt</p> and saved the file.
  4. logs totally work but the view is showing "this is testt" (which is supposed to show me earlier when i saved the file at the beginning)

What am I doing wrong??

Environment

React Hot Loader version: ^4.6.3

  1. node -v: 8.14.0
  2. npm -v: 6.4.1
  3. yarn -v: 1.12.3 (I'm using yarn)
./index.js
const render = Component =>
	ReactDOM.render(
		<Provider store={store}>
			<I18nextProvider i18n={i18n}>
				<App/>
			</I18nextProvider>
		</Provider>,
		document.getElementById('root'));

render(App);

if (module.hot) module.hot.accept('pages/App',() => render(App));
./App.js
const HomePage = lazy(() => import("pages/HomePage"));
const DynamicPage = lazy(() => import("pages/DynamicPage"));
const NoMatchPage = lazy(() => import("pages/NoMatchPage"));

<Router>
        <Suspense fallback={<div>loading...</div>}>
             <Switch>
                  <Route exact path="/" render={() => <HomePage />} />
                  <Route path="/dynamic" render={() => <DynamicPage />} />
                  <Route render={() => <NoMatchPage />} />
             </Switch>
        </Suspense>
</Router>
//console : When I save files, the log says It is up to date but It isn't re-rendering the component.
[WDS] App updated. Recompiling...
client:224 [WDS] App hot update...
log.js:24 [HMR] Checking for updates on the server...
log.js:24 [HMR] Updated modules:
log.js:24 [HMR]  - ./src/pages/HomePage/HomePage.js
log.js:24 [HMR]  - ./src/pages/HomePage/index.js
log.js:24 [HMR]  - ./src/pages/App.js
log.js:24 [HMR] App is up to date.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions