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

Switch back to MutableMap to avoid scatter map bug #2438

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

JakeWharton
Copy link
Collaborator

Sometimes the scatter-based maps can return values from other keys when inserting a new key. See https://issuetracker.google.com/issues/378077858.


  • CHANGELOG.md's "Unreleased" section has been updated, if applicable.

Comment on lines +239 to +241
idToNode[lastCreatedId.value] = ReuseNode(
widgetId = lastCreatedId,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch to local which already has the same value as change.id

changesAndNulls: Array<Change?>,
pooled: ProtocolNode<W>,
) {
// Reuse the node.
pooled.id = widgetId
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to lookup the Create, we already have a member with the new ID.

@JakeWharton
Copy link
Collaborator Author

Took a quick look around at other scatter-based map and set usage. They don't have this long-lived put/remove pattern.

childrenTag = ChildrenTag.Root,
idToNode[lastCreatedId.value] = ReuseNode(
widgetId = lastCreatedId,
// This is the root of the reuse tree, so it will never have a children tag from a parent.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Sometimes the scatter-based maps can return values from other keys when inserting a new key. See https://issuetracker.google.com/issues/378077858.
@JakeWharton JakeWharton force-pushed the jw.mutable-map.2024-11-08 branch from 2052c85 to 0fc9fff Compare November 8, 2024 19:46
@JakeWharton JakeWharton enabled auto-merge (squash) November 8, 2024 19:47
@squarejesse squarejesse disabled auto-merge November 8, 2024 19:50
@squarejesse squarejesse merged commit 64af090 into trunk Nov 8, 2024
10 checks passed
@squarejesse squarejesse deleted the jw.mutable-map.2024-11-08 branch November 8, 2024 19:51
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