React-Splitters icon indicating copy to clipboard operation
React-Splitters copied to clipboard

getSize() throws error on getBoundingClientRect

Open don-p opened this issue 6 years ago • 10 comments

Seems related to: https://github.com/martinnov92/React-Splitters/issues/9

I see this error when resizing the browser window, in a view that contains a second instance of Splitter:

Uncaught TypeError: Cannot read property 'getBoundingClientRect' of null
    at Splitter._this.getSize (Splitter.js:205)

From what I can see, this may be a problem with multiple instances of the Splitter object in one application. For example, in my application I have two main tabs which each contain a Splitter. I see that the Splitter.componentDidMount adds a window resize event listener, that calls _this.getSize. It seems to me that this could cause a problem, since only the currently-rendered object should be responding to window.resize events.

And, a non-rendered Splitter object will have a null reference to its paneWrapper property -

      ref: function ref(node) {
        return _this.paneWrapper = node;
      }

@martinnov92 Have you tested this component in a case like this, with two instances of Splitter in visible and hidden parent tabs?

Thanks, Don

don-p avatar Feb 08 '19 22:02 don-p

Any update of this issue ?

JeanBeaurepaire avatar Feb 21 '19 15:02 JeanBeaurepaire

I am also getting this issue with just one splitter.

MarinaGurevich avatar Apr 03 '19 18:04 MarinaGurevich

@martinnov92 I'm also getting the same error when splitter is visible and parent component is visible.

Revathigb avatar Apr 12 '19 15:04 Revathigb

Hello, I will look at this very soon. Thank you for your patience.

martinnov92 avatar Apr 13 '19 09:04 martinnov92

Hi! Thank you for the best splitter!

We did some research with @arch7tect and noticed, that this error relates to window.addEventListener('resize', this.getSize);. When the splitter is unmounted, the window resizer listener still exists. Addition window.removeEventListener('resize', this.getSize); in componentWillUnmount has to resolve the problem.
#22

michael-whi avatar Jul 15 '19 16:07 michael-whi

Hi! Thank you for the best splitter!

We did some research with @arch7tect and noticed, that this error relates to window.addEventListener('resize', this.getSize);. When the splitter is unmounted, the window resizer listener still exists. Addition window.removeEventListener('resize', this.getSize); in componentWillUnmount has to resolve the problem. #22

Is version 1.2 include this update? I meet this error also when I npm latest version

phoon0901 avatar Aug 14 '19 09:08 phoon0901

Hi! Thank you for the best splitter! We did some research with @arch7tect and noticed, that this error relates to window.addEventListener('resize', this.getSize);. When the splitter is unmounted, the window resizer listener still exists. Addition window.removeEventListener('resize', this.getSize); in componentWillUnmount has to resolve the problem. #22

Is version 1.2 include this update? I meet this error also when I npm latest version

No, it doesn't. The pull request is still opened, unfortunately.

michael-whi avatar Aug 14 '19 10:08 michael-whi

Hi! Thank you for the best splitter! We did some research with @arch7tect and noticed, that this error relates to window.addEventListener('resize', this.getSize);. When the splitter is unmounted, the window resizer listener still exists. Addition window.removeEventListener('resize', this.getSize); in componentWillUnmount has to resolve the problem. #22

Is version 1.2 include this update? I meet this error also when I npm latest version

No, it doesn't. The pull request is still opened, unfortunately.

Anyway to directly use this? I directly added componentWillUnmount into Splitter.tsx in component folder but it is not worked.

phoon0901 avatar Aug 15 '19 00:08 phoon0901

Hi! Thank you for the best splitter! We did some research with @arch7tect and noticed, that this error relates to window.addEventListener('resize', this.getSize);. When the splitter is unmounted, the window resizer listener still exists. Addition window.removeEventListener('resize', this.getSize); in componentWillUnmount has to resolve the problem. #22

Is version 1.2 include this update? I meet this error also when I npm latest version

No, it doesn't. The pull request is still opened, unfortunately.

Anyway to directly use this? I directly added componentWillUnmount into Splitter.tsx in component folder but it is not worked.

As a workaround, you can create a custom splitter and extend m-react-splitter, then define listener removing in componentWillUnmount. Something like that:

import Splitter from 'm-react-splitters'

export default class CustomSplitter extends Splitter {
    componentWillUnmount() {
        window.removeEventListener('resize', this.getSize);
    }
}

michael-whi avatar Aug 15 '19 07:08 michael-whi

Hi all, i can solved this issue. If anyone still facing this issue please mail me "[email protected]"

ghost avatar Nov 16 '22 09:11 ghost