loadable-components icon indicating copy to clipboard operation
loadable-components copied to clipboard

I get an error. Check the render method of `InnerLoadable`

Open pavliha opened this issue 7 years ago • 16 comments

When I try to navigate to other async component in react router I get image And when I reload the page everything works again Issue reproduced here https://github.com/pavliha/ssr-app.

pavliha avatar May 27 '19 07:05 pavliha

Hello @pavliha, I gave a quick look in your code and everything looks fine for me. Maybe someone else could give a look and help you!

gregberge avatar May 28 '19 07:05 gregberge

Thanks for checking out this case @neoziro. For some reason await import('./TestScene') returns empty object image

And later I figured out this is react-hot-loader breaks everything. How react-hot-loader affects module import is still a question. I think this is because I'm using webpack-dev-middleware instead of webpack-dev-server. Looks like react-hot-loader and webpack-dev-middleware does not work together as expected

pavliha avatar May 28 '19 13:05 pavliha

Double checked - loadable and RHL are not playing well together (no automatic reload), but no error is present.

@pavliha - could you disable source maps and give me final sources for TestScene - let's find the root cause.

theKashey avatar May 28 '19 22:05 theKashey

@theKashey. I've updated the repo maybe something was missing. Hmm maybe I could write some steps to reproduce an issue. Just in case

  1. yarn install
  2. rename .env.example to .env
  3. yarn start
  4. open http://localhost:2000
  5. click on test link

In the updated repo. I have disabled source maps and connected sources of the @loadable/component via webpack aliases

image

pavliha avatar May 29 '19 08:05 pavliha

I have a similar setup but with webpack-dev-server and loadable works with react-hot-loader. It is webpack-dev-middleware that causing the problems. Official documentation for react-hot-loader says it's not yet supported

image

pavliha avatar May 29 '19 08:05 pavliha

That's now "official" documentation, as long as we dropped a ball on it a bit, but it's supported - the problem is more about proper configuration. I will try to fill this gap in the documentation.

theKashey avatar May 29 '19 10:05 theKashey

@theKashey thank you a lot. Have you tried to find core problem in this particular case?

pavliha avatar May 29 '19 10:05 pavliha

Not yet.

theKashey avatar May 29 '19 12:05 theKashey

Long story short - everything is very bad:

  • RHL thinks that HMR is "active"
  • RHL does not sees Index and Test as a "registered" variables
  • RHL does a false positive merge of Index and Test, thinking that Index "isReady"(exists in the cache), and then calling requireSync for Test. Don't ask.

theKashey avatar May 29 '19 23:05 theKashey

  • HMR is open after importing a new code block. That's expected behavior
  • False positive for forwardRef. Something to be fixed.

theKashey avatar May 29 '19 23:05 theKashey

  • fix created. Will release a new version of RHL in an hour. No changes from loadable-component are required.

theKashey avatar May 29 '19 23:05 theKashey

I have the same issue. I am using react-router-dom.

` const HomePage = loadable(() => import(/* webpackPrefetch: true / '../pages/AuthPages/HomePage')); const RepresentativeRegistrationPage = loadable(() => import(/ webpackPrefetch: true */ '../pages/AuthPages/RepresentativeRegistrationPage') );

    <Route
      exact
      path={ROUTES.HOME_PAGE}
      render={(props) =>
         (!isAuthentificated ? <Redirect to={ROUTES.LOGIN} /> : <HomePage {...props} />)}
    />

    <Route
      exact
      path={ROUTES.REPRESENTATIVE_REGISTRATION}
      render={(props) => !isAuthentificated ? <Redirect to={ROUTES.LOGIN} /> : 
      <RepresentativeRegistrationPage {...props} />}
    />

`

When I have Redirect outside loadable It works fine.

But when I am trying return inside Loadable component from to a have error.

image

Anatoool avatar May 30 '19 12:05 Anatoool

I am on it. Just cant merge and deploy anything at 00:06

theKashey avatar May 30 '19 14:05 theKashey

React-Hot-Loader v4.9.0 should fix the issue.

theKashey avatar Jun 02 '19 02:06 theKashey

@theKashey man you are THE BEST!!!. Thank you so much. Issue resolved

pavliha avatar Jun 04 '19 10:06 pavliha

I should say - sorry for affecting you all by this issue for a few months...

theKashey avatar Jun 04 '19 10:06 theKashey