Skip to content

Hotfix: fix infinite update loop crashing the map - #34

Merged
TomProkop merged 1 commit into
mainfrom
hotfix-media-loop
Jul 23, 2026
Merged

TomProkop merged 1 commit into
mainfrom
hotfix-media-loop

Conversation

@TomProkop

Copy link
Copy Markdown
Member

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

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>
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.

1 participant