Skip to content

fix: deepMerge no longer mutates its arguments - #350

Open
richard-willis-chevin wants to merge 3 commits into
fabien0102:mainfrom
richard-willis-chevin:fix/deep-merge-mutates-arguments
Open

fix: deepMerge no longer mutates its arguments#350
richard-willis-chevin wants to merge 3 commits into
fabien0102:mainfrom
richard-willis-chevin:fix/deep-merge-mutates-arguments

Conversation

@richard-willis-chevin

@richard-willis-chevin richard-willis-chevin commented Aug 24, 2026

Copy link
Copy Markdown

Fixes #349.

It now builds a new object and mutates neither argument, and only recurses when both sides are plain objects — so arrays are replaced rather than merged by index, and FormData/File bodies pass through untouched.

The existing "should merge two objects" test is unchanged and still passes, so the behaviour #284 added is preserved. The four new tests all fail against the previous implementation.

Also updated the committed example output and one inline snapshot, both of which embed the generated helper.

deepMerge merged into its target and returned it, and also assigned into
its source. Generated hooks call deepMerge(fetcherOptions, variables),
and fetcherOptions comes from a single useContext() call per hook
instance, so that object is shared by every call of the hook. Each call
therefore leaked its payload into the next: concurrent writes could all
send the last one's body, sequential writes carried stale fields from
the previous one, and the caller's own variables object was rewritten
behind its back. Every request stayed well formed and succeeded, so the
corruption was silent.

deepMerge now builds a new object and mutates neither argument. It also
only recurses when both sides are plain objects, so arrays are replaced
rather than merged by index, and FormData/File bodies are passed through
untouched.

The existing merge test is unchanged and still passes, so the behaviour
fabien0102#284 introduced is preserved.

Closes fabien0102#349
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.

deepMerge mutates its arguments, corrupting request payloads across calls

1 participant