Hotfix: fix infinite update loop crashing the map - #34
Merged
Merged
Conversation
MediaMarkers.tsx was passing an inline arrow function as markerRef, giving it a new identity on every render. useClusterer relies on ref callback identity staying stable per marker (documented in its own comment) - a fresh function each render makes React detach/reattach every AdvancedMarker's ref on every render, which triggers the setMarkers state update in a loop and blows past React's max update depth, crashing the whole page with any geotagged media on the map. Fixed by caching one stable ref-callback function per post id (same pattern useClusterer itself uses internally), reading the post to tag onto the marker from a ref instead of capturing it in a new closure. Verified: npm run build, npm run lint. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause: MediaMarkers.tsx passed an inline arrow function as markerRef, giving it a new identity every render. useClusterer relies on ref-callback identity staying stable per marker - a fresh function each render makes React detach/reattach every AdvancedMarker ref every render, triggering the setMarkers state update in a loop and exceeding React's max update depth (error #185), crashing any page rendering the map with geotagged media.
Fix: cache one stable ref-callback function per post id (same pattern useClusterer uses internally), reading the post to tag from a ref instead of capturing it in a new closure each render.
Verified: npm run build, npm run lint.
Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com