Pointer
I only wanted to edit this draft, so why did the original settings change too?
I only wanted to edit this draft, so why did the original settings change too?
Assigning the original to the draft adds another name for the same object. It does not copy the contents.
Editing contents versus changing targets: Updating draft.theme.mode changes the object it reaches. Assigning a different object to draft only changes that name’s target; it does not rewrite the original object. Assigning primitive values such as numbers also differs from sharing mutable objects.
Shallow copying isolates only the first level: { ...original } creates a new outer object, but theme still points to the original theme object. Updating draft.theme.mode therefore still affects the original. Unlike direct assignment, the outer objects are now separate.
What pointers mean in Git: A Git branch records its target commit. Usually HEAD points to the current branch, which points to a commit. This is a target-recording analogy, not a memory address. Switching branches also updates working-tree files and may be blocked by uncommitted edits. Not duplicating the whole project does not mean files remain unchanged.
Editing settings and cancelling also changes the original configuration. Check whether the draft shares the original or nested objects, then isolate edits in a way appropriate to the data types. Verify that editing nested fields and cancelling preserves the original, and that settings update only on Save.
Build in 3D. Put your computer to work.