Skip to content

Conversation

@MichaelSun48
Copy link
Contributor

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.

@MichaelSun48 MichaelSun48 requested a review from a team as a code owner August 28, 2024 16:28
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Aug 28, 2024
viewId,
]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [tabListState, navigate, organization.slug, query, sort, viewId]);
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@leeandher leeandher left a 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 pathname to navigate, 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!

@MichaelSun48
Copy link
Contributor Author

  • Rather than passing pathname to navigate, 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.

@leeandher
Good idea! I think I'd prefer to make this change in a separate PR since this PR prevents the issue stream from crashing, and I'd want to spend some extra time testing after changing all of the navigates to what you suggested. I added your ErrorBoundary suggestion in the last commit though.

Copy link
Member

@scttcper scttcper left a 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

@MichaelSun48 MichaelSun48 merged commit 868d7b6 into master Aug 28, 2024
@MichaelSun48 MichaelSun48 deleted the msun/customViews/fixInfiniteRerenderUponQueryChange branch August 28, 2024 18:54
ArthurKnaus pushed a commit that referenced this pull request Aug 29, 2024
)

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.
MichaelSun48 added a commit that referenced this pull request Sep 3, 2024
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.
@github-actions github-actions bot locked and limited conversation to collaborators Sep 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants