Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'getBoundingClientRect' of undefined #177

Open
kumardennis opened this issue Jan 11, 2021 · 9 comments
Open

Comments

@kumardennis
Copy link

<Container style={{ height: "500px" }}> <Section style={{ background: "#d3d3d3" }} minSize={100} /> <Bar size={10} style={{ background: "#888888", cursor: "col-resize" }} /> <Section style={{ background: "#d3d3d3" }} minSize={100} /> </Container>
copied the code from the example, still getting error.

@tiagomnferreira-zz
Copy link

Having exactly the same problem, waiting for an answer

@Arif-un
Copy link

Arif-un commented Jun 9, 2021

I got this error after enabling React.StrictMode

@dombo3
Copy link

dombo3 commented Jun 10, 2021

Same issue for me.

@Gibbo3771
Copy link

I am currently in the process of fixing this on my fork since the maintainer seems to be...gone.

Not quite sure what is going on yet, inside the Container component childrenProps array contains duplicate items (exactly two of everything) and since this is supposed to map 1-1 with childrenInstance array, we end up with every second array element being undefined.

You can see the log output below. createID is only called 3x which is correct.

screenie

I will investigate and see if I can figure out why this is happening.

@domogami
Copy link

I am having the same issue and I think it does have to do with React.StrictMode

@viveleroi
Copy link

The problem is that the author is pushing section/bar props into a private array (childrenProps) held in Container.tsx and then relying on the length as a unique ID for each section/bar.

In normal mode, this "works" and generates IDs like 0, 1, 2, 3, etc. That's not a great solution especially when you want react to be "deterministic" and always produce the same result.

Furthermore, the author is relying on one-to-one mapping of an array index to these IDs. So there's a loop: this.childrenProps.forEach((childProps, index) => { const element = this.childrenInstance[index]; - this is making an assumption that there will always be an ID for the corresponding index and that it relates to the element mapping the author setup.

This all fails because React.StrictMode calls life cycle methods twice, meaning the items pushed onto the array are duplicating. This causes IDs to generate as 1, 3, 5, 7. That breaks the internal mapping and causes the 'getBoundingClientRect' of undefined error.

It looks to me like this repo is dead so I don't expect any fixes with this. But if anyone wants to take a shot, this can save you some debugging. I would imagine it'd be better for components to generate their own ID. Sadly the IDs are used all over the library for array sizes and indexes so this isn't a small change.

I will need a good resizer lib in the coming months, though and may do my own. I like the features with this but am not sure about some of the execution and the requirement of rxjs.

@runjuu
Copy link
Contributor

runjuu commented Nov 13, 2022

@viveleroi Excellent explanation!

Hi, I am the original author of this library. Unfortunately I left LeetCode a few years ago and now I don't have access to this repository, so I have to make a Fork for further maintenance.

Try running the code in your local environment and see if there are any problems. I will continue to improve it over the next few weeks, so feel free to give me any feedback!

By the way, RxJS is not really necessary and I will replace it with a lighter solution in a later update.

@viveleroi
Copy link

Excellent news! Thanks. Since this issue was reported two years ago and had no author comments I assumed this was fully dead.

Dropping rxjs would probably be best because while it's a great library, it's overkill for this and best not to add large dependencies. Oddly enough I want to use rxjs myself in our application but sometimes I struggle to think of real use cases.

Once you can publish your fork to NPM somewhere I'll try it in our actual prototype app and let you know. Our current app is in AngularJS and I had to write the resizer lib myself so I'm looking forward to not doing that when we redo it in react! Appreciate your effort.

@runjuu
Copy link
Contributor

runjuu commented Jan 3, 2023

Phew, almost done! After removing the redundant dependencies, the overall size was reduced from 28.9 kB to 4.3 kB 🎉 . Also, a new documentation site is under construction, come and have a look 😆!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants