Skip to content
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 Marker position update comparison #1139

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

agentpietrucha
Copy link

@agentpietrucha agentpietrucha commented Aug 3, 2024

Problem

When rendering list of markers from state array using .map and later updating that state, all markers positions will be updated even though no existing marker has changed its position. In some cases this is causing flickering of the markers' icons. (This is noticeable especially when using MarkerClusterGroup)

Example: https://stackblitz.com/edit/vitejs-vite-lonc2p?file=src%2FMap.tsx (Notice markers' flicker after around 3 secs after the page loads. The most bottom marker will have changed opacity from 1 to 0.5 after 3 secs. I implemented changes from this PR in that example. With those changes there is no more flickering)

Fix

Current check to decide whether or not to update the position is props.position !== prevProps.position, which compares by reference. To update the marker's position only when position value changes, the validation should compare objects by values instead. I added 3 different checks for 3 potential position types: type LatLngExpression = LatLng | LatLngLiteral | LatLngTuple;

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