Skip to content

fix: make walk visit every node in the tree - #2305

Open
cpruijsen wants to merge 1 commit into
mobxjs:masterfrom
cpruijsen:fix/issue-1433
Open

cpruijsen wants to merge 1 commit into
mobxjs:masterfrom
cpruijsen:fix/issue-1433

Conversation

@cpruijsen

Copy link
Copy Markdown

What does this PR do and why?

walk now visits untouched model, array, and map children before their parent.
Previously, an undefined storedValue caused traversal to skip those subtrees and sometimes visit only the root.

In src/core/mst-operations.ts, walk reads .value for ObjectNode children to initialize their instances.
Scalar children retain the storedValue path, so traversal does not resolve reference targets or call custom reference resolvers.
Instance initialization can run afterCreate and afterAttach hooks.

Fixes #1433.

Steps to validate locally

The three tests in __tests__/core/1433.test.ts check exact visit paths and order for untouched nested models, arrays, maps, and references.
All three fail without the fix and pass with it in development and production modes.

walk only visited the root node because ObjectNode.storedValue is
undefined until the instance is lazily created, so the isStateTreeNode
check never passed for untouched children. Reading .value on object
nodes materializes them; scalar nodes still use .storedValue since
their .value can differ (references resolve to the target node).
@coolsoftwaretyler

Copy link
Copy Markdown
Collaborator

Thanks @cpruijsen - I'll take a look soon!

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.

Walk is not walking the tree

2 participants