fix: stack overflow on pre-existing Symbol circular references (#1106) - #1306
Open
dyk1454683243-sudo wants to merge 1 commit into
Open
dyk1454683243-sudo wants to merge 1 commit into
dyk1454683243-sudo wants to merge 1 commit into
Conversation
current() recursively walked nested non-draft objects with no cycle guard and always used strict iteration for those nodes. Pre-existing Symbol child-to-parent links (immerjs#1106) therefore overflowed, even when produce() itself was already safe via handleValue's handledSet. Remember already-snapshotted objects and keep the same iteration mode when descending, and add tests for produce() and current() on this shape. Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
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.
Fixes #1106.
Problem
Starting in 10.0.4, Immer walks symbol keys. Objects that use symbols for child-to-parent links (skipped by
JSON.stringify/ Immer 9) then hit Maximum call stack size exceeded.On current
main,produce()itself is already safe:handleValuetracks visited objects.current()was not. It:strictwas not passed down), so symbol links were followed even whensetUseStrictIteration(false)(the default).That is the remaining overflow for the issue’s data shape — e.g.
produce(parent, d => { d.name = "x"; current(d) }).Change
In
current():WeakMap) so circular refs (including symbol keys) reuse the snapshot instead of recursing forever.No other finalization / copy behavior is changed.
Tests
__tests__/symbol-circular.jscovers the issue’s cases:produceon parent, nested child, and child-as-rootcurrent()after parent/child updatessetUseStrictIteration(true)and strict shallow copyproduceleaks proxy objects when symbols are present #1087)Notes
Circular references added inside a recipe were already fine; this is only about pre-existing symbol cycles. Plain (enumerable) circular refs remain unsupported, as documented.