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

Fix #183 #184

Merged
merged 1 commit into from
Sep 28, 2024
Merged

Fix #183 #184

merged 1 commit into from
Sep 28, 2024

Conversation

Minnowo
Copy link
Contributor

@Minnowo Minnowo commented Sep 28, 2024

Fixes #183.

This only updates the state when the height has changed. This prevents the infinite render loop.

if (ref.current) {
setHeight((old) => ({...old, [name]: ref.current!.getBoundingClientRect().height}));
const currentHeight = ref.current && ref.current.getBoundingClientRect().height;
if (currentHeight != null && currentHeight !== height) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've adjusted this, to check outside of the setState. The react docs weren't clear it guaranteed that setState with the same value doesn't force a rerender.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does skip rerendering: https://react.dev/reference/react/useState#setstate-caveats

If the new value you provide is identical to the current state, as determined by an Object.is comparison, React will skip re-rendering the component and its children. This is an optimization. Although in some cases React may still need to call your component before skipping the children, it shouldn’t affect your code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although in some cases React may still need to call your component before skipping the children

Okay, then "reexecute" the compomennt instead of rerender, but yeah doesn't really matter as the new impl. behaves the same.

@jmattheis jmattheis merged commit e145ced into traggo:master Sep 28, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

Maximum update depth exceeded when scrolling down
2 participants