Issues with async resolve · Issue #57 · ctrlplusb/react-async-component · GitHub
Skip to content

Issues with async resolve #57

Open

Description

@mschipperheyn

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.

Activity

  1. baldurh commented on Nov 16, 2017

    @baldurh

    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

  2. baldurh commented on Nov 30, 2017

    @baldurh

    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

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