Repository navigation
fix(js,ts): a package import follows the page, and stops at a monorepo's own edge - #3166
Merged
Merged
Conversation
…o's own edge Two ways an import of a repository's own package landed on the wrong code. The side of the wire: the `exports` reader tries `node` first, so react's `fixtures/flight/src/index.js`, built for the page, took `react-server-dom-webpack/client` as `client.node.js` and its `encodeReply` from the Edge client that re-exports. A file that reads `document` or `window` now takes the entry's `browser` condition; any other file reads it as before. The install: react's `compiler/` has a package.json with `workspaces` of its own, so it installs an npm `react` and `@types/jest`. Its files linked to `packages/react/index.js` by the outer workspace's name, and its bare `expect` to the outer `scripts/jest/typescript/jest.d.ts`. A folder whose package.json or pnpm-workspace.yaml declares workspaces is now a root of its own: a bare import from inside it doesn't reach the outer workspace's packages, and a guess by name doesn't leave it. A member of the outer workspace is no root, since package managers don't nest workspaces. The check is on the winner, not the pool: taking candidates out of the pool left lone ones, which answered 149 `this.setState()` calls in the outer root with a test stub. Validation: tests fail on main and pass here. A/B against 4499d00: react 19 moved to the browser variant, 736 removed, all of them from `compiler/` to outside it; excalidraw, ai-chatbot, pot-desktop, vscode-be, vben, dub, flask, gin identical. Index CPU: level (see the PR). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
colbymchenry
added a commit
that referenced
this pull request
Nov 18, 2026
…member
With `"workspaces": ["../sibling"]`, the workspace loader read
`../sibling/package.json` and registered its name (`left-pad2`) as a package
of the project. expandWorkspaceGlob returned an exact entry as written, with
no check that it stays inside the root, and a glob like `../*` walked the
parent folder. Nothing under `../sibling` is indexed, so an import of
`left-pad2` resolved to no file; but as a workspace member it no longer read
as an outside package's (isExternalImport answers false for one), and the
name matcher bound `import { pad } from 'left-pad2'` and the call through it
to the project's own unrelated `src/util.ts` `pad` (exact-match, 0.9).
A workspace member is a folder of the project. expandWorkspaceGlob now
returns nothing for an entry that leaves the root after normalizing
(`../x`, `../*`, `packages/../../x`) or is absolute; package.json's array
and Yarn's object form and pnpm-workspace.yaml all go through it. The import
is then an outside package's, as with no `workspaces` field at all. The
path-dependency walk already skipped `file:` targets outside the project.
The issue's comment saying main at b300cce no longer reproduced it doesn't
hold here: b300cce built on this machine (Node 22, kernel off), v1.6.3's
sources (Node 22 and 24) and the published 1.6.3 (kernel on and off) all
link the call, and nothing on this path depends on the platform (traced:
the member map, workspaceImportTargets, isExternalImport). The name-match
gate PR #3166 added only applies to nested workspace roots.
Validation:
- workspace-outside-project.test.ts: the issue's layout, `../*`,
`packages/../../sibling`, Yarn's object form, pnpm-workspace.yaml and an
absolute path name no member and leave `run()` with no callee; a project
with `./packages/*` beside `../sibling` keeps its inside member and its
call. All 6 fail on main and pass here.
- Workspace and resolution area tests: 17 files, 587 passed.
- The issue's own repro script: control, inproject and outside all print
`run() calls: []`.
- A/B against v1.6.3 sources (3 rounds, interleaved): taxonomy, excalidraw
(a yarn workspace), vscode-be, and controls flask and gin all produce
byte-identical graphs; index-time medians moved within this machine's
noise in both directions.
PR #3130 (@johnhldiver-beep) proposed the same guard.
Fixes #3093
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
colbymchenry
added a commit
that referenced
this pull request
Nov 18, 2026
…member
With `"workspaces": ["../sibling"]`, the workspace loader read
`../sibling/package.json` and registered its name (`left-pad2`) as a package
of the project. expandWorkspaceGlob returned an exact entry as written, with
no check that it stays inside the root, and a glob like `../*` walked the
parent folder. Nothing under `../sibling` is indexed, so an import of
`left-pad2` resolved to no file; but as a workspace member it no longer read
as an outside package's (isExternalImport answers false for one), and the
name matcher bound `import { pad } from 'left-pad2'` and the call through it
to the project's own unrelated `src/util.ts` `pad` (exact-match, 0.9).
A workspace member is a folder of the project. expandWorkspaceGlob now
returns nothing for an entry that leaves the root after normalizing
(`../x`, `../*`, `packages/../../x`) or is absolute; package.json's array
and Yarn's object form and pnpm-workspace.yaml all go through it. The import
is then an outside package's, as with no `workspaces` field at all. The
path-dependency walk already skipped `file:` targets outside the project.
The issue's comment saying main at b300cce no longer reproduced it doesn't
hold here: b300cce built on this machine (Node 22, kernel off), v1.6.3's
sources (Node 22 and 24) and the published 1.6.3 (kernel on and off) all
link the call, and nothing on this path depends on the platform (traced:
the member map, workspaceImportTargets, isExternalImport). The name-match
gate PR #3166 added only applies to nested workspace roots.
Validation:
- workspace-outside-project.test.ts: the issue's layout, `../*`,
`packages/../../sibling`, Yarn's object form, pnpm-workspace.yaml and an
absolute path name no member and leave `run()` with no callee; a project
with `./packages/*` beside `../sibling` keeps its inside member and its
call. All 6 fail on main and pass here.
- Workspace and resolution area tests: 17 files, 587 passed.
- The issue's own repro script: control, inproject and outside all print
`run() calls: []`.
- A/B against v1.6.3 sources (3 rounds, interleaved): taxonomy, excalidraw
(a yarn workspace), vscode-be, and controls flask and gin all produce
byte-identical graphs; index-time medians moved within this machine's
noise in both directions.
PR #3130 (@johnhldiver-beep) proposed the same guard.
Fixes #3093
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
colbymchenry
added a commit
that referenced
this pull request
Nov 18, 2026
…member (#3351) With `"workspaces": ["../sibling"]`, the workspace loader read `../sibling/package.json` and registered its name (`left-pad2`) as a package of the project. expandWorkspaceGlob returned an exact entry as written, with no check that it stays inside the root, and a glob like `../*` walked the parent folder. Nothing under `../sibling` is indexed, so an import of `left-pad2` resolved to no file; but as a workspace member it no longer read as an outside package's (isExternalImport answers false for one), and the name matcher bound `import { pad } from 'left-pad2'` and the call through it to the project's own unrelated `src/util.ts` `pad` (exact-match, 0.9). A workspace member is a folder of the project. expandWorkspaceGlob now returns nothing for an entry that leaves the root after normalizing (`../x`, `../*`, `packages/../../x`) or is absolute; package.json's array and Yarn's object form and pnpm-workspace.yaml all go through it. The import is then an outside package's, as with no `workspaces` field at all. The path-dependency walk already skipped `file:` targets outside the project. The issue's comment saying main at b300cce no longer reproduced it doesn't hold here: b300cce built on this machine (Node 22, kernel off), v1.6.3's sources (Node 22 and 24) and the published 1.6.3 (kernel on and off) all link the call, and nothing on this path depends on the platform (traced: the member map, workspaceImportTargets, isExternalImport). The name-match gate PR #3166 added only applies to nested workspace roots. Validation: - workspace-outside-project.test.ts: the issue's layout, `../*`, `packages/../../sibling`, Yarn's object form, pnpm-workspace.yaml and an absolute path name no member and leave `run()` with no callee; a project with `./packages/*` beside `../sibling` keeps its inside member and its call. All 6 fail on main and pass here. - Workspace and resolution area tests: 17 files, 587 passed. - The issue's own repro script: control, inproject and outside all print `run() calls: []`. - A/B against v1.6.3 sources (3 rounds, interleaved): taxonomy, excalidraw (a yarn workspace), vscode-be, and controls flask and gin all produce byte-identical graphs; index-time medians moved within this machine's noise in both directions. PR #3130 (@johnhldiver-beep) proposed the same guard. Fixes #3093 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Two ways an import of a repository's own package landed on the wrong code.
The side of the wire: the
exportsreader triesnodefirst, so react'sfixtures/flight/src/index.js, built for the page, tookreact-server-dom-webpack/clientasclient.node.jsand itsencodeReplyfromthe Edge client that re-exports. A file that reads
documentorwindownowtakes the entry's
browsercondition; any other file reads it as before.The install: react's
compiler/has a package.json withworkspacesof itsown, so it installs an npm
reactand@types/jest. Its files linked topackages/react/index.jsby the outer workspace's name, and its bareexpectto the outer
scripts/jest/typescript/jest.d.ts. A folder whose package.json orpnpm-workspace.yaml declares workspaces is now a root of its own: a bare import
from inside it doesn't reach the outer workspace's packages, and a guess by name
doesn't leave it. A member of the outer workspace is no root, since package
managers don't nest workspaces. The check is on the winner, not the pool:
taking candidates out of the pool left lone ones, which answered 149
this.setState()calls in the outer root with a test stub.Validation
4499d007:react's removed edges all run from
compiler/to outside it: 455 intopackages/react, 133 calls ofexpectanditintoscripts/jest, and the rest guesses by name (expectonto a fixture'ssetupTests.js,componentonto a property inpackages/react-client).compiler/package.jsondeclaresworkspaces, and its packages pinreactto an npm build, so none of these is what its code runs.The 19 moved:
fixtures/flightandfixtures/flight-parceltoclient.browser.js, and test files that usedocumentwithreact-dom/servertoserver.browser.js, which Jest's jsdom environment selects too. No other file reading the page changed: a package needs abrowsercondition for this to matter.Left out: a file of the outer root reaching into
compiler/by a name guess. Vetoing that direction too moved answers around on react, so it stays as it was.97cd3800, all six on4499d007: 853 files passed, 6 skipped; 10,610 tests passed, 2 expected fail, 87 skipped, 0 failed; 4 workers, Vitest 4.1.11,CODEGRAPH_KERNEL_EXPECT=1. This PR's own test files pass on this head.🤖 Generated with Claude Code