Merged
Conversation
When deep-watching objects, oldValue and value were the same reference, so by callback time oldValue reflected the already-mutated state. Fix: reuse the JSON.stringify result already computed for deep tracking, store it, and JSON.parse it back as oldValue when the callback fires. Zero additional stringify calls — only a JSON.parse when the callback actually fires. Closes #3293 Related: #4406, #3046, #3617 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
$watch,oldValuewas the same reference asvalue. By callback time, both reflected the already-mutated state.oldValue.barshowed'bob'instead of'baz'.JSON.stringifyresult already computed for deep tracking (line 68), store it, andJSON.parseit back asoldValuewhen the callback fires. Zero additional stringify calls.$watchtests pass.The bug
oldValue = valuestores a proxy reference. For objects, both point to the same reactive proxy — the old state is lost.The fix
Follows
entangle.jsprecedent (JSON.parse(JSON.stringify())). Same JSON edge-case limitations already exist on line 68.Closes #3293. Related: #4406 (original PR by @Suall1969 who identified the fix direction), #3046, #3617.
Test plan
deep $watch receives old value— object nested property changedeep $watch receives old value for arrays— array push mutationdeep $watch receives old value with null— null to object transition$watchtests still passentangleandx-datatests pass (no regressions)🤖 Generated with Claude Code