Skip to content

fix(js,ts): a package import follows the page, and stops at a monorepo's own edge - #3166

Merged
colbymchenry merged 1 commit into
mainfrom
claude/fx-package-side-and-root
Nov 1, 2026
Merged

colbymchenry merged 1 commit into
mainfrom
claude/fx-package-side-and-root

Conversation

@colbymchenry

Copy link
Copy Markdown
Owner

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, pass here, on this head.
  • No extraction change, so nothing to compare between engines.
  • A/B against 4499d007:
Repo Added Removed Moved
react, where it was found 0 736 19
excalidraw, ai-chatbot, pot-desktop, vscode-be, vben, dub 0 0 0
Controls: flask, gin 0 0 0

react's removed edges all run from compiler/ to outside it: 455 into packages/react, 133 calls of expect and it into scripts/jest, and the rest guesses by name (expect onto a fixture's setupTests.js, component onto a property in packages/react-client). compiler/package.json declares workspaces, and its packages pin react to an npm build, so none of these is what its code runs.

The 19 moved: fixtures/flight and fixtures/flight-parcel to client.browser.js, and test files that use document with react-dom/server to server.browser.js, which Jest's jsdom environment selects too. No other file reading the page changed: a package needs a browser condition 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.

  • Index CPU: the six together, median of 3 interleaved: react 131.0 to 132.4 s (+1.1%, rounds spread 112 to 145 s; wall -6.4%), vscode-be 43.8 to 44.0 s (+0.6%), django 68.0 to 66.4 s (-2.3%). Level within noise.
  • Suite: the six PRs of this set ran as one stack, 97cd3800, all six on 4499d007: 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

…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
colbymchenry merged commit 3bd9949 into main Nov 1, 2026
@colbymchenry
colbymchenry deleted the claude/fx-package-side-and-root branch November 1, 2026 04:11
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>
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