fix(arborist): invalid filterNode crash under the linked strategy#9637
Merged
owlstronaut merged 2 commits intoJun 24, 2026
Merged
Conversation
Under the linked strategy the diff's actual side is a synthesized wrapper tree. When includeRootDeps was active (--workspaces=false or -w <ws> --include-workspace-root), the root-dep filter nodes were pulled from this.actualTree, whose root is the real actual tree rather than the wrapper, tripping Diff.calculate's invalid filterNode guard. Use only the ideal-side root-dep targets when the linked wrapper is in use, matching the existing workspace-node handling.
Global installs are normalized to the shallow strategy in the Arborist constructor, but reify() re-derived the linked flag from the raw per-call installStrategy option, bypassing that normalization. A global install passed installStrategy:'linked' would engage the unsupported linked path: re-installing an already-present global package tripped Diff.calculate's invalid filterNode guard, and once the guard was bypassed the isolated reifier deleted the global package instead of materializing it. Honor the global-to-shallow normalization in reify() so global installs never use the linked strategy.
owlstronaut
approved these changes
Jun 24, 2026
Contributor
|
🎉 Backport to |
owlstronaut
pushed a commit
that referenced
this pull request
Jun 24, 2026
) Backport of #9637 to `release/v11`. Co-authored-by: Manzoor Wani <manzoorwani.jk@gmail.com>
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.
In continuation of our exploration of using
install-strategy=linkedin the Gutenberg monorepo, which powers the WordPress Block Editor.Under
install-strategy=linked, several common installs failed withnpm error invalid filterNode: outside idealTree/actualTree, with no workaround besides dropping the linked strategy. Hoisted handled all of them. This fixes two distinct paths that both produced that error.Why
A linked reify diffs the ideal tree against a synthesized actual wrapper (
#linkedActualForDiff) rather thanthis.actualTree.Diff.calculaterejects any filter node whose root is neither the ideal nor the actual it was given, so a filter node taken from the realthis.actualTreeis "outside" the diff and throws.Two places fed it such nodes:
--workspaces=falseand-w <ws> --include-workspace-rootgo through theincludeRootDepsbranch of_diffTrees(), which collected root-dep edge targets from boththis.idealTreeandthis.actualTree. The actual-side targets are rooted at the real actual tree, not the wrapper, so they tripped the guard. The siblingincludeWorkspacesbranch already accounted for this; the root-dep branch did not.A global install with a per-call
installStrategy: 'linked're-engaged the linked path even though the constructor normalizes global installs toshallow(the linked layout is unsupported for globals). Re-installing an already-present global package then hit the global explicit-request branch, which pushes actual-side nodes, and tripped the same guard. Suppressing the crash there was worse: the isolated reifier does not materialize the global layout and removed the package instead.How
_diffTrees()now iterates only the ideal tree for root-dep filter nodes when the linked wrapper is in use, matching the existing workspace-node handling. The ideal-side nodes are sufficient to scope the diff, and the post-reify orphan sweep continues to prune deps removed from the manifest.reify()now honors the constructor's global-to-shallow normalization when deriving thelinkedflag, so a global install never engages the linked path regardless of a per-callinstallStrategy. Global installs fall back to shallow, which materializes and upgrades packages correctly. No change to the global explicit-request branch is needed once global is never linked.References
Fixes #9614
Part of #9608