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.

Top level updates being blocked - with solution

See original GitHub issue

Version

4.2.2 react-router-dom (current unpkg latest)

Test Case

Broken: https://jsfiddle.net/samsch/1ghyyxx9/4/

Expected: https://jsfiddle.net/samsch/1ghyyxx9/5/

Steps to reproduce

Clicking links should cause routes to re-render, and the path should be redirected on load.

Expected Behavior

Regular ol’ routing. Route "" should always show, and Route / should show initially after immediate redirect. Click on To / and Route / should show, click To /r1 and Route /r1 should show.

Actual Behavior

In the broken fiddle, no navigation updates occur at all after initial render.

The Problem

Passing a unique prop to the PureComponent (as outlined by Dealing with Update Blocking) doesn’t work because App doesn’t re-render and the children passed to BrowserRouter aren’t updated. Context is updated in the working fiddle because context doesn’t need render to run to trigger componentWillReceiveProps.

Basically, using React Router this way doesn’t work without extra non-obvious pieces (wrapping the children of BrowserRouter in a withRouter component, or forcing App to re-render somehow) show in The Solution.

I think the docs fail to address this potential problem, and the usage examples point to passing (effectively) static children to BrowserRoute.

The Solution

https://jsfiddle.net/samsch/1ghyyxx9/6/

The children of BrowserRouter need to be wrapped in something that will re-render when routing is updated (withRouter).

Feature Request

A docs reference to this problem in Dealing with Update Blocking could be helpful, and could point at the solution above, or:

Could a render prop option be added to the Router component? It doesn’t even need to pass any props (though it could pass the router/location). So instead of

const RouterRenderer = withRouter(props => props.render());
...
<Router>
  <RouterRenderer render={() => ...children...} />
</Router>

It would be just

<Router render={() => ...children...} />

Real World

My real world case isn’t a PureComponent, but Redux connect()ed components which are part of the layout tree above and around routing components. https://gist.github.com/samsch/8a7f818e72bbad9079da0f67a8619434

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Vinlockcommented, Jan 26, 2018

Thank you so much!!! This helped me solve my issue!

0reactions
timdorrcommented, Mar 13, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

Top level updates being blocked - with solution #5895 - GitHub
In the broken fiddle, no navigation updates occur at all after initial render. The Problem. Passing a unique prop to the PureComponent (as ......
Read more >
KB5004442—Manage changes for Windows DCOM Server ...
The first phase of DCOM updates was released on June 8, 2021. In that update, DCOM hardening was disabled by default. You can...
Read more >
Fix Chrome update problems & failed updates - Google Support
Make sure software updates aren't blocked from going online. Make sure tools.google.com and dl.google.com aren't blocked. Reboot your computer.
Read more >
Windows 10 update blocked by annoying settings error
The Windows 10 May 2020 update, the largest update of the year thus far, is being blocked on some system due to unsupported...
Read more >
Why are Java applications blocked by your security settings?
An application with self-signed certificate is blocked by default. Applications of this type present the highest level of risk because publisher is not ......
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