Skip to content

fix: restore draft state when current() throws - #1397

Open
Alanmupa wants to merge 1 commit into
immerjs:mainfrom
Alanmupa:fix/current-restores-drafting
Open

Alanmupa wants to merge 1 commit into
immerjs:mainfrom
Alanmupa:fix/current-restores-drafting

Conversation

@Alanmupa

Copy link
Copy Markdown

Hi! I found that a producer which catches an exception from current(draft) can accidentally mutate its original state afterward. When a getter throws during snapshotting, the draft stays marked as finalized. A later read of an unchanged child can then return the original object instead of a draft.

I restore the prior finalized flag in finally, covering exceptions during both the shallow copy and recursive snapshot. The regression test catches a throwing getter, removes it, and verifies that a later nested increment updates the result while preserving the original value.

I ran the source and built-package test suites and checked formatting. I used Codex to help prepare and validate the patch.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant