fix: keep marker keys unique when repeated across worlds#2233
Open
Yusufihsangorgel wants to merge 1 commit into
Open
fix: keep marker keys unique when repeated across worlds#2233Yusufihsangorgel wants to merge 1 commit into
Yusufihsangorgel wants to merge 1 commit into
Conversation
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.
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.
Closes #2229.
The problem
When the map is zoomed out far enough that the world repeats horizontally,
MarkerLayerdraws each marker once per visible world.getPositioned(worldShift)builds a
Positionedfor every world and passedkey: m.keyunchanged, so amarker that has a
keyproduced several siblingPositionedwidgets with thesame key inside the layer's
Stack: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), sofind.byKeyandper-marker widget identity are unchanged, and derive a distinct key from the
world shift for the repeated copies:
Tests
Added
test/layer/marker_key_worlds_test.dart: a wide viewport at low zoomrepeats the world, the keyed marker is drawn more than once, no duplicate-key
exception is thrown, and
find.byKeystill resolves to exactly one widget. Ichecked 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.