fix: deepMerge no longer mutates its arguments - #350
Open
richard-willis-chevin wants to merge 3 commits into
Open
fix: deepMerge no longer mutates its arguments#350richard-willis-chevin wants to merge 3 commits into
richard-willis-chevin wants to merge 3 commits into
Conversation
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
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.
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/Filebodies 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.