Skip to content

Conversation

@narsaynorath
Copy link
Member

@narsaynorath narsaynorath commented Jul 23, 2024

We should only be triggering the set state for the alert to undefined if we're not already undefined, i.e. prevents an infinite loop of renders.

The page alert context provides setters that were getting re-created each time the state changed. Wrap the setters in useCallback so the reference to the functions are always the same. This way, hooks that list these functions as dependencies don't go rampant.

@narsaynorath narsaynorath requested a review from a team July 23, 2024 16:52
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Jul 23, 2024
@codecov
Copy link

codecov bot commented Jul 23, 2024

Bundle Report

Changes will increase total bundle size by 330 bytes ⬆️

Bundle name Size Change
app-webpack-bundle-array-push 28.18MB 330 bytes ⬆️

@DominikB2014
Copy link
Contributor

@narsaynorath shouldnt setting state to the same value yield no rerenders?

@codecov
Copy link

codecov bot commented Jul 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.14%. Comparing base (26e6464) to head (0ac8262).
Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #74737   +/-   ##
=======================================
  Coverage   78.14%   78.14%           
=======================================
  Files        6730     6730           
  Lines      300110   300110           
  Branches    51623    51623           
=======================================
  Hits       234529   234529           
- Misses      59256    59259    +3     
+ Partials     6325     6322    -3     
Files Coverage Δ
...tatic/app/utils/performance/contexts/pageAlert.tsx 62.85% <100.00%> (ø)

... and 1 file with indirect coverage changes

@narsaynorath
Copy link
Member Author

@DominikB2014 I agree and thought it was weird so I dug a bit deeper and it looks like it's because of referential inequality. Basically when we trigger the setPageInfo function, it creates a new setPageInfo callback. I think we could potentially fix this by wrapping the settings with useCallback

@narsaynorath narsaynorath enabled auto-merge (squash) July 23, 2024 17:26
@narsaynorath narsaynorath merged commit 99b7210 into master Jul 23, 2024
@narsaynorath narsaynorath deleted the nar/fix/insights-caches-page-alert-rerendering branch July 23, 2024 17:29
@github-actions github-actions bot locked and limited conversation to collaborators Aug 8, 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