Repository navigation
Conversation
This branch has not been deployed
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.
Map#getOrInsertandMap#getOrInsertComputedcurrently bypass Immer's Map state. On a draft, they can return the fallback for an existing key and silently discard inserted entries. On a produced Map, they can mutate its contents even though the Map is frozen and ordinarysetcalls throw.Draft Maps inherit these native methods, which read the empty native Map storage created by
super()instead of Immer's tracked contents. This implements the methods through the existing draft operations and includes them in the frozen Map mutation guards. Each method is exposed only when the runtime supports it, so older runtimes keep their existing API.For example, starting with
new Map([['a', 1]]):Before, the existing-key call returns
9andnextcontains only['a', 1]. After, it returns1andnextalso contains['b', 2]. Callingnext.getOrInsert('c', 3)now rejects mutation consistently withnext.set('c', 3).The computed form preserves native callback validation and key handling, skips the callback for existing keys, and applies the callback result even if the callback inserted the same key. Returning existing values through the draft's
getalso preserves nested drafting.The failure reproduces on Immer 11.2.9 and current main without external services. Set composition methods are outside this patch.