Skip to content

fix: keep marker keys unique when repeated across worlds#2233

Open
Yusufihsangorgel wants to merge 1 commit into
fleaflet:masterfrom
Yusufihsangorgel:fix/2229-marker-key-duplicate-across-worlds
Open

fix: keep marker keys unique when repeated across worlds#2233
Yusufihsangorgel wants to merge 1 commit into
fleaflet:masterfrom
Yusufihsangorgel:fix/2229-marker-key-duplicate-across-worlds

Conversation

@Yusufihsangorgel

Copy link
Copy Markdown

Closes #2229.

The problem

When the map is zoomed out far enough that the world repeats horizontally,
MarkerLayer draws each marker once per visible world. getPositioned(worldShift)
builds a Positioned for every world and passed key: m.key unchanged, so a
marker that has a key produced several sibling Positioned widgets with the
same key inside the layer's Stack:

Duplicate keys found.
Stack(...) has multiple children with key [<'m-1'>].

Markers without a key were never affected. Only keyed markers, and only once
they became visible in more than one world.

The fix

Keep the caller's key on the main world (worldShift == 0), so find.byKey and
per-marker widget identity are unchanged, and derive a distinct key from the
world shift for the repeated copies:

key: m.key == null || worldShift == 0
    ? m.key
    : ValueKey((m.key, worldShift)),

Tests

Added test/layer/marker_key_worlds_test.dart: a wide viewport at low zoom
repeats the world, the keyed marker is drawn more than once, no duplicate-key
exception is thrown, and find.byKey still resolves to exactly one widget. I
checked it both ways: the test fails without the fix and passes with it. Full
suite green (118 tests).


I used AI tooling to help investigate and draft this. I have reviewed the
change, wrote the test, and take full responsibility for it.

Closes fleaflet#2229. When the world repeats horizontally, MarkerLayer draws each
marker once per visible world; getPositioned passed key: m.key unchanged, so a
keyed marker produced sibling Positioned widgets with the same key in the
layer's Stack (Duplicate keys). Keep the caller's key on the main world
(worldShift == 0) and derive ValueKey((m.key, worldShift)) for repeated copies,
so find.byKey and per-marker identity are unchanged.
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.

Markers with set keys will cause duplicate keys when visible across multiple worlds

1 participant