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.

Cannot read property 'getBoundingClientRect' of null

See original GitHub issue

My entire app is this:

import React from 'react'
import ReactDOM from 'react-dom'
import Photo from '../components/photo'
import {createClient} from 'contentful'
import ScrollableAnchor from 'react-scrollable-anchor'

// import { configureAnchors } from 'react-scrollable-anchor'

// Offset all anchors by -60 to account for a fixed header
// and scroll more quickly than the default 400ms
// configureAnchors({offset: -60, scrollDuration: 200, keepLastAnchorHash: true})


const client = createClient({
  space: '[redacted]',
  accessToken: '[redacted]'
})


const App = ({assets}) => {
  return (
    <div className="list">
      {
        assets.map(asset =>
          <ScrollableAnchor id={asset.fields.id}>
            <div style={{height: '1000px'}}>test</div>
            {/* <Photo photo={asset}  /> */}
          </ScrollableAnchor>
        )
      }
    </div>
  );
};
  

document.addEventListener('DOMContentLoaded', () => {
  client.getAssets()
  .then((response) => ReactDOM.render(<App assets={response.items}/>, document.getElementById('app')))
  .catch(console.error)
})



I get this error after a scroll stops:

Uncaught TypeError: Cannot read property 'getBoundingClientRect' of null
    at getElementOffset (scroll.js:14)
    at doesElementContainScrollTop (scroll.js:29)
    at scroll.js:88
    at Array.forEach (<anonymous>)
    at getBestAnchorGivenScrollLocation (scroll.js:86)
    at Manager.handleScroll (Manager.js:76)
    at later (func.js:15)
getElementOffset @ scroll.js:14
doesElementContainScrollTop @ scroll.js:29
(anonymous) @ scroll.js:88
getBestAnchorGivenScrollLocation @ scroll.js:86
Manager.handleScroll @ Manager.js:76
later @ func.js:15
setTimeout (async)
(anonymous) @ func.js:20

(context: I just want something that changes the URL of the page to have a fragment corresponding with whatever picture is currently in the viewport, so that if the link is shared, the browser will scroll to that specific picture. Shouldn’t be hard, right?)

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

7reactions
TrebuhDcommented, Jul 4, 2018

I’m having the same problem. I tried wrapping my components in <div>s and converting them to stateless components, nothing works.

Edit: I managed to solve it - in my case it was caused by a child of <ScrollableAnchor /> being null.

4reactions
moritzmockcommented, Oct 5, 2019

@TrebuhD thx for the hint, I used a React.Fragment:

<ScrollableAnchor id="contact">
   <>
      {"CONTACT"}
   </>
</ScrollableAnchor>

After I changed them to a <div> all worked fine!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'getBoundingClientRect' of null
I get this error: Cannot read property 'getBoundingClientRect' of null . I use this function getBoundingClientRect , because in my project I ...
Read more >
Cannot read property 'getBoundingClientRect' of null #100
Hi! I'm getting sometimes this error in console Uncaught TypeError: Cannot read property 'getBoundingClientRect' of null How can I fix this?
Read more >
Throwing Cannot read property 'getBoundingClientRect' of ...
The error keeps coming from Sentry from a user using windows xp and chrome v49.0.2623, and several users using windows 10 and Edge...
Read more >
TypeError: Cannot read property 'getBoundingClientRect' of null
Hi,. The issue I am experiencing looks similar to (see link below), except I am using the angular 2+ diagrams component. ... It...
Read more >
TypeError: Cannot read property 'getBoundingClientRect' of null
Suspected problems and effort to solve this: Error message: I get the same error message “TypeError: Cannot read property 'getBoundingClientRect' of null” from ......
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