-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(custom-views): Fix infinite rerendering upon unsaved changes #76672
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(custom-views): Fix infinite rerendering upon unsaved changes #76672
Conversation
| viewId, | ||
| ]); | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [tabListState, navigate, organization.slug, query, sort, viewId]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this still cause the same issue since were calling tabListState.setSelectedKey() inside which will cause tabListState to update and refire the hook?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point - intuitively I feel like it should too, but in my testing that doesn't occur. I'm pretty sure this is because this useEffect's behavior depends on the url query, and if tabListState.setSelectedKey() is called, it changes the query in a way such that the subsequent time this useEffect runs, it would not result in tabListState.setSelectedKey() being called again. Sorta like reaching a state of equilibrium after one unnecessary rerender if that makes sense?
I think you've still got a point that leaving tabListState as a dependency is more likely to cause issues down the line, even if its stable now, so I'll remove it in the next commit.
leeandher
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few more things before a green stamp!
- Rather than passing
pathnametonavigate, I'd just use the current location. I think theres a search params hook in v6 react router but that might not be available yet, so this is the next best. It'll prevent weird bugs if we ever use this component on a different page, or change the path or something.
const location = useLocation()
navigate({...location, query: {...location.query, modifed: True}})- If the entire page is crashing when the component fails, and it's only supplementary to the data on the page as a whole, it would probably be worth wrapping it in an
ErrorBoundary. This is always true, but especially so for these changes in high traffic areas!
@leeandher |
scttcper
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sometimes for things you want to only happen on init it's easier to use a ref that enforces it is only applied once
This PR replaces any navigation that was done in custom views to use the location/pathname from `useLocation`, rather than just hard coding the same pathname every time (`organizations/<org-slug>/issues/`). There are routing improvements that need to be made (which were alluded to in [this PR](#76672 (comment))), but this seems to fix some compatibility issues with RR 6.
This PR fixes an infinite rerendering bug that caused the issue stream to crash. This was caused by a circular dependency in a useEffect. Fix is to remove those dependencies.