Skip to content

fix: replace unstable ObjectKey(tileRenderer) with stable TileKey#2195

Open
braindamagedman wants to merge 1 commit intofleaflet:masterfrom
braindamagedman:fix/incorrect-tile-keys
Open

fix: replace unstable ObjectKey(tileRenderer) with stable TileKey#2195
braindamagedman wants to merge 1 commit intofleaflet:masterfrom
braindamagedman:fix/incorrect-tile-keys

Conversation

@braindamagedman
Copy link
Copy Markdown

Previously tiles were keyed with ObjectKey(tileRenderer), but TileRenderer instances are recreated on every build. Because of that, the key was unstable even when the logical tile did not change. The root cause of this issue was introduced in commit
182c4fc when unbounded horizontal scroll was introduced.

As a result, Flutter could not match the new widget with the existing element and treated the tile as a new widget. This led to repeated disposal and recreation of _TileState instead of updating the existing state.

The fix replaces that key with a stable TileKey based on TileImage identity and positionCoordinates. This preserves _TileState for the same rendered tile and avoids unnecessary remounting.

Before:
before

After fix:
after

You can check simple code to reproduce before/after examples here:
https://github.com/braindamagedman/flutter_map/tree/test/tile-key

@JaffaKetchup
Copy link
Copy Markdown
Member

Oo, thanks for this, we should've caught that. That's a useful debug text, we might add that to the example app.

We need to make sure that this isn't preventing the tiles from changing when we actually do want the state to change, since we've had far too many issues there in the past, but I think your fix should be good.

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.

2 participants