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.

'getBoundingClientRect' of null error when using together with react-router

See original GitHub issue

I have nested StickyContainers. One global (that is available all the time) and two containers that are inside routes. When switching those two routes back and forth quickly, I will get the following error:

Uncaught TypeError: Cannot read property 'getBoundingClientRect' of null

in the following line: https://github.com/captivationsoftware/react-sticky/blob/43a370d2810215de1b7d9c7a5986d860c52206e1/src/Container.js#L47

Seems like react-sticky is trying to access an unmounted(?) container and therefore is not getting the node.

The StickyContainer inside the routes is wrapped inside a div (that is inside the route component):

<Router render={() => (
  <div>
    <StickyContainer>
       // ...
     </StickyContainer>
  </div>
)}>

I guess the easiest solution for this is to wrap the code that throws the error with:

if (this.node) {
  // ...
}

So this error doesn’t happen anymore. For me it doesn’t break the functionality, It just throws the error.

Or maybe I have done something wrong with using the StickyContainer.

Can you give me any feedback on this?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

9reactions
TheXardascommented, Aug 30, 2017

Please, merge a fix for this!

9reactions
tchockcommented, Jul 15, 2017

I did a fix for this (for the node being null), that we use in our code. Because currently this repo is not active developed anymore I would suggest to use my fork. I created a runnable version, that you can install with changing the version reference of react-sticky in the package.json file to:

"react-sticky": "tchock/react-sticky#6.0.1-1",

After that you need to do npm install or yarn install.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'getBoundingClientRect' of null
getBoundingClientRect () inside a useEffect, which reads it when the component mounts. I was getting the same error.
Read more >
useref cannot read property of null - You.com | The AI Search ...
Error using useeffect and useref TypeError: Cannot read property 'getBoundingClientRect' of null. Asked Nov 19, 2020 • 0 votes 1 answer. QUESTION ANSWERS....
Read more >
Hooks FAQ - React
What do Hooks mean for popular APIs like Redux connect() and React Router? Do Hooks work with static typing? How to test components...
Read more >
21 Essential React.js Interview Questions and Answers | Toptal®
What sort of tools might you use in the build steps to optimize the compiled output React code? View answer.
Read more >
Modal - Ant Design
Additionally, if you need show a simple confirmation dialog, you can use antd. ... You could set footer to null if you don't...
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