#453
fix: stop spec replay from mutating message parts
Problem
buildSpecFromParts (react, vue, solid) and devtools extractSpecFromParts applied patch values by reference, so later patches wrote into the message parts themselves. Building a spec from the same parts again, on a remount or in the devtools generation switcher, re-applied index and append patches (/state/posts/0, /children/-) on top of the mutated values and duplicated state items and children. The spec from the first build changed too, because it shares those arrays. The system prompt teaches this pattern for state arrays. Svelte was not affected, since it already snapshots each patch.
Changes
- Deep-copy part data before applying it in all four replay functions. The copy is JSON, because
structuredClonethrows on Vue reactive proxies. - A replay test per package that builds the same parts twice and expects the same spec; each one fails on main.
Visual proof
useJsonRenderMessage with the same parts, mounted, unmounted and mounted again:
Activity
4ctatereviewed8d ago
found the same as ctate! LGTM 🔥
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment