Skip to content

fix(arborist): handle links with cleared targets - #9820

Open
ljepson wants to merge 1 commit into
npm:latestfrom
ljepson:pr/stale-link-matches
Open

fix(arborist): handle links with cleared targets#9820
ljepson wants to merge 1 commit into
npm:latestfrom
ljepson:pr/stale-link-matches

Conversation

@ljepson

@ljepson ljepson commented Jul 29, 2026

Copy link
Copy Markdown

Hit this reifying a pnpm-shaped node_modules, npm died with:
TypeError: Cannot read properties of null (reading 'matches') out of Node.matches()

Reassigning a node's root clears target on every link pointing at it, so you can end up with a link where isLink is true but target is null.

matches() dereferenced it. Guarding both sides makes a targetless link just not match, which is what the caller wanted anyway. Test builds two links to a shared target and reassigns the target's root to clear both. It throws without the fix.

I left the guard inside the existing this.isLink branch rather than restructuring, a plain Node compared against a Link still falls through the same way, so placement and dedupe are untouched.

@ljepson
ljepson requested review from a team as code owners July 29, 2026 16:44
@ljepson
ljepson marked this pull request as draft July 29, 2026 16:52
@ljepson
ljepson force-pushed the pr/stale-link-matches branch 2 times, most recently from d3cc3ca to 87a13ec Compare July 30, 2026 19:14
Reassigning a node's root clears `target` on every link pointing at
it, leaving a link with `isLink` true but no target. Comparing such a
link in `matches()` crashed with `TypeError: Cannot read properties
of null (reading 'matches')` instead of reporting no match.
@ljepson
ljepson force-pushed the pr/stale-link-matches branch from 87a13ec to 5d43dc1 Compare July 30, 2026 19:20
@ljepson
ljepson marked this pull request as ready for review July 30, 2026 19:32
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.

1 participant