Skip to content

Fix: Accidental mutation of old model causes invalid JSON Patch #802

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

Merged
merged 2 commits into from
Aug 13, 2022

Conversation

rmorshea
Copy link
Collaborator

Closes: #801

Checklist

Please update this checklist as you complete each item:

  • The changelog.rst has been updated with any significant changes.
  • GitHub Issues which may be closed by this Pull Request have been linked.

@rmorshea rmorshea changed the title Json patch workaround Fix: Accidental mutation of old model causes invalid JSON Patch Aug 13, 2022
@rmorshea rmorshea force-pushed the json-patch-workaround branch 2 times, most recently from 6b2ab39 to d1c6d37 Compare August 13, 2022 06:45
accidental mutation of old parent model caused invalid JSON patches
@rmorshea rmorshea force-pushed the json-patch-workaround branch 10 times, most recently from 1e146fa to 3eedca3 Compare August 13, 2022 20:36
distutils has also been deprecated
@rmorshea rmorshea force-pushed the json-patch-workaround branch from 3eedca3 to ef593d6 Compare August 13, 2022 20:38
@rmorshea rmorshea merged commit 2f0bb98 into main Aug 13, 2022
@rmorshea rmorshea deleted the json-patch-workaround branch August 13, 2022 21:06
Comment on lines +233 to +243
# need to add this model to parent's children without mutating parent model
old_parent_model = parent.model.current
old_parent_children = old_parent_model["children"]
parent.model.current = {
**old_parent_model,
"children": [
*old_parent_children[:index],
new_state.model.current,
*old_parent_children[index + 1 :],
],
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be the reason why VDOM children won't render if they follow a component?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be related to the fact that I'm replacing the parent model on line 236? The fact that I'm not propagating this change up the model parents is probably a problem, but I can't quite see why that's causing your problem where the children are not rendering.

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.

Accidental mutation of old model causes invalid JSON Patch
2 participants