Skip to content
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

Issues with async resolve #57

Open
mschipperheyn opened this issue Sep 12, 2017 · 2 comments
Open

Issues with async resolve #57

mschipperheyn opened this issue Sep 12, 2017 · 2 comments

Comments

@mschipperheyn
Copy link

mschipperheyn commented Sep 12, 2017

I tried out the async resolve on a React Universally project and I ran into a lot of nasty little issues that were hard to debug. I'm still not sure what exactly was going wrong. And I would like to find out how to avoid this

The idea was basically to reduce the size of the initial loaded component and take advantage of code splitting by using

export default asyncComponent({
  // include home and about route in same chunk e.g main
  resolve: () =>
    new Promise(resolve =>
      require.ensure(
        [],
        (require) => {
          resolve(require('./AdminRoute'));
        },
        'admin',
      ),
    ),
  LoadingComponent: () => <Loading />,
});

instead of

export default asyncComponent({
  resolve: () => System.import('./AdminRoute'),
  LoadingComponent: () => <Loading />,
});

However, I ran into issues like loading a location and then navigating to a another location and getting errors like this:

screen shot 2017-09-12 at 08 25 43

which translates to:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

This only happened on production.

I initially thought this was due to caching since we are using CloudFlare on the front end, but I added some rules there to prevent caching of /index.html, and I still had the issues.

So, in the end I resorted to going back to big fat deployment file since the pressure was on to deliver. But I would really like to understand how to deal with chunking properly so these errors don't occur and if they do are easier to debug.

@baldurh
Copy link

baldurh commented Nov 16, 2017

We just had the exact same experience! Also code splitting routes. Only happens on production with a similar setup.
We had to back out as well. This was our second attempt at this after having a similar experience with faceyspacey/react-universal-component

Our error was: Cannot read property 'call' of undefined

@baldurh
Copy link

baldurh commented Nov 30, 2017

OK so our problem was that the webpack boilerplate chunk hash was not being updated when the chunk contents changed. We were using webpack-md5-hash which is being used in react-universally.
See this issue for details: erm0l0v/webpack-md5-hash#9
Also: webpack/webpack#1856

We discovered that people were getting two versions of the same file. When we purged the cache on both fastly and cloudflare everything went back to normal.

We removed webpack-md5-hash from our project and using HashedModuleIdsPlugin and ChunkManifestWebpackPlugin and did a similiar thing as found here:
ctrlplusb/react-universally#472

See webpack’s caching guide here: https://webpack.js.org/guides/caching/

Hope this helps somebody 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants