-
-
Notifications
You must be signed in to change notification settings - Fork 850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested Produce: Changes to inner draft not reflected in outer draft #694
Comments
So the more I think about this, the more I convince myself that this behavior is working as designed.
Since the main idea behind In my example I am essentially discarding the results of the inner reducer, when I should instead merge that result with the outer reducer's draft object, e.g.:
That being said, I think this actually conflicts with some of the past discussions around this topic (#377, #433, #533), specifically #533 (comment). I'd like to leave this open in hopes that one of the project maintainers can confirm the expected behavior in this scenario. This could also be a good opportunity to add to the docs to prevent any confusion in the future (I'll be happy to submit a PR once the expected behavior is confirmed). |
Your analysis sounds about right, note that in your example just |
Thanks for the reply!
Are you saying that there is no need to merge the inner and outer drafts with something like
...because it doesn't. :) Without |
Sorry, I meant to type |
Got it! Let me put together a PR to clarify this scenario in the docs so that there's no confusion going forward. Thanks again! |
🎉 This issue has been resolved in version 7.0.15 🎉 The release is available on: Your semantic-release bot 📦🚀 |
For anyone trying to navigate use of nested calls to produce, I made a codepen demo of things that do and don't work |
🐛 Bug Report
Nested produce calls are not working as expected; changes made to the "inner" draft do not reflect on the "outer" draft.
My use case is calling a sub-reducer from a main reducer, where the main reducer makes some mutations to its draft, and then passes the draft as a base state to a sub-reducer where further changes to the draft will be made. For example:
In this example, my expectation is that
newState
contains the changes made by both theouterReducer
and theinnerReducer
, but the draft changes made ininnerReducer
are not reflected.Link to repro
https://codesandbox.io/s/immer-sandbox-forked-mqjns
or
https://codesandbox.io/s/immer-sandbox-forked-6jptr
To Reproduce
Pass a draft state as base state to
produce
, e.g. by nesting one or moreproduce
calls.You can also paste this test case into an existing test suite:
Observed behavior
Changes made to inner draft object are not reflected in the outer draft object.
Expected behavior
Reading the discussions in #433 and #533, I would expect that changes made to nested draft objects should be reflected in the top-most draft object.
Environment
setUseProxies(true)
setUseProxies(false)
(ES5 only)The text was updated successfully, but these errors were encountered: