question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to properly release a new version of app that uses react-universal-component?

See original GitHub issue

I successfully use react-universal-component in production, but I am faced with a problem related to releasing new versions of my app.

My case: I have a released version of application. I open an app in a browser. Then I release a new version of app. After that I trigger loading of some component in opened app (that was opened before new release). And I am getting an error.

Looks like when I open app before release it loads main.SOME_HASH.js, that contains a list of chunks for lazy components. Each of this chunk contains hash in file name.

When I release new version of app, some (or all) hashes in file names of chunks can be changed. But because I opened app before release, main.SOME_HASH.js contains an old list of chunks. So when I trigger loading of component in my app, react-universal-component tries to load chunks for old version. And this chunk doesn’t exist on server side any more (in docker image in my case).

As a solution, I see an ability to distinguish network error and 404 from server. In this case I can show error page to user if there is a network error, but if server returns 404 code while downloading chunk for lazy component I can trigger window.location.reload(), that will cause downloading new version of app (downloading new version of main.SOME_NEW_HASH.js that contains a new list of chunks).

So, I suggest to add response info (at least response code) to error that react-universal-component passes to ErrorComponent.

I am not 100% sure that this is right solution. Maybe anyone can suggest another option.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
ScriptedAlchemycommented, Feb 20, 2019

Production shouldn’t have a build but just start from static files.

0reactions
braskacommented, Feb 23, 2019

I would like to avoid storing old chunks (storage is another one infrastructure element that can increase cost and requires maintenance). Best case scenario for me: reload page if it tries to download chunk that was presented in old docker container/image, but in current (new) running container not presented.

My question: how can I detect there 404 error returned for server for old chunk?

This is simplified version of my current implementation:

const ErrorLoadingPage = ({ error }) => {
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    if (error && error.request) {
      window.location.reload();
    } else {
      setLoading(false);
    }
  });

  if (loading) {
    return <LoadingPage />;
  }

  return (
    <StyledMainTemplate>
      <Helmet>
        <title>Error while loading</title>
      </Helmet>
      <Wrapper>
        <p>Error occurred</p>
        <Button
          primary
          onClick={() => {
            window.location.reload(true);
          }}
        >
          Retry
        </Button>
      </Wrapper>
    </StyledMainTemplate>
  );
};

But the problem of this implementation that page will be reloaded even if there is no internet connection. User will see default browser page like this: image

But I want to show ErrorLoadingPage if user lost internet connection and reload page only if 404 was returned from server.

It would be great if I have ability to replace if (error && error.request) { ... } statement with if (error && error.response && error.response.code === 404) { ... }.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-universal-component - npm
Latest version : 4.5.0, last published: 2 years ago. Start using react-universal-component in your project by running `npm i ...
Read more >
Versioning Policy - React
Instead, we release new features in minor versions. That means that minor releases are often more interesting and compelling than majors, despite their ......
Read more >
Up and Running with Universal Components | HackerNoon.com
To publish a new version of the package run lerna publish from the root directory of the project (not the universal-components directory).
Read more >
Building a Universal Higher-Order Component Page Loader ...
Using the Loading HOC in my React App. With the universal loading component created, it's time to add it to the component that...
Read more >
lung-react-universal-component - npm package - Snyk
An important project maintenance signal to consider for lung-react-universal-component is that it hasn't seen any new versions released to npm in the past ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found