Skip to content

fix(build): declare @types/react for the React libraries whose typings import it - #37066

Merged
os-zhuang merged 4 commits into
mainfrom
claude/project-thread-xwd5h9
Nov 25, 2026
Merged

os-zhuang merged 4 commits into
mainfrom
claude/project-thread-xwd5h9

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Irene · project thread
Fixes #37015

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:Mac 上的开发者(包括你)从干净检出跑控制台构建,不再停在国际化包的类型错误上;用户无感。
  • 为什么做:解决你在 Mac 上验收控制台构建时被卡住的问题,那张验收卡要等这个修好才能继续。
  • 出错会怎样:只影响依赖安装与类型检查,不改任何运行时代码;出问题时整笔撤回即可恢复原状。
  • 要你做什么:合并后请在 Mac 上重跑一次控制台构建验收。

What changes

  • Root cause (measured on Linux, pnpm 10.31.0 at a73edb3): 31 packages in the lockfile ship .d.ts files that import react but declare no @types/react (React 19 ships no types). From their pnpm store directories those imports resolved only through pnpm's hidden hoist (node_modules/.pnpm/node_modules). With the hoist off, TypeScript reports nothing for the library (skipLibCheck) and degrades every React type in it to any/{}: useContext(I18nContext) became {} (the maintainer's TS2339 at packNamespace.ts), LucideProps lost className, the input-otp context became unknown, cmdk callbacks became implicit any.
  • Fix: pnpm-workspace.yaml gains a packageExtensions block declaring @types/react (plus @types/react-dom for react-router and next) as a peer of each of the 31 packages. pnpm then links the workspace's own @types/react into each package's store directory, so the types resolve the same way under any hoist setting. pnpm-lock.yaml is the regenerated consequence: packageExtensionsChecksum plus peer suffixes on snapshot keys; no version moves, still exactly one @types/react@19.3.0 and one @types/react-dom@19.3.0.
  • Why this fix and not the other two candidates:
    • A typed local read in packNamespace.ts fixes one line out of a family of 31 packages. The console build would stop at the next one (@object-ui/components, measured below).
    • public-hoist-pattern for @types/* is still hoisting. It works only while the package's real path sits under the project root, so it fails under a global virtual store. It also makes @types/react visible to every workspace package that does not declare it.
    • A peer, not a dependency: a peer resolves to the version the importer already has. A dependency would resolve on its own and could pull a second @types/react, which would split React's types.
  • Guard: ui/packages/i18n/src/__tests__/react-typings-own-resolution-37015.test.ts asks TypeScript's own module resolver where react resolves from the typings of each third-party dependency of @object-ui/i18n. It uses a host that cannot see above the node_modules directory holding that library, so it judges the no-hoist layout whatever the running install hoisted. A pin asserts that react-i18next is among the packages checked.
  • Fixture rebuild: ui/scripts/__tests__/check-lockfile-integrity.test.ts: sample (b) pins the snapshot key '@ai-sdk/react@4.0.121(react@19.3.0)(zod@4.6.7)', which the peer moves to '@ai-sdk/react@4.0.121(@types/react@19.3.0)(react@19.3.0)(zod@4.6.7)'. One string is changed to the key now in the lockfile; nothing else in that file changes. The seat granted the surface for this edit (claim amendment 7140294701).

Tests

Before / after on the hoist-disabled install (fail → pass)

Install: pnpm install --config.hoist=false --ignore-scripts (no node_modules/.pnpm/node_modules).

  • Before (a73edb3): pnpm turbo run build --filter=@object-ui/i18n → exit 2, src/namespaces/packNamespace.ts(302,48): error TS2339: Property 'i18n' does not exist on type '{}'.
  • Before: the console build with --continue (turbo run build:dist --filter=@objectstack/console) → exit 2. 26 tasks failed. The root errors were i18n (above) and @object-ui/components: TS2339 className on LucideProps, TS18046 on the input-otp context, TS7006 on a cmdk callback. The rest cascaded from those two packages having no declarations.
  • Before: turbo run type-check over the 25 ui packages that consume a family library → exit 2, 48 tasks failed.
  • After (with the fix, same install flags): the console build → exit 0, Tasks: 77 successful, 77 total. The type-check sweep → exit 0, Tasks: 100 successful, 100 total. No ui type-check task was replayed from cache.
  • Census (a scratch script that walks the live store dirs): before, 31 of 88 store packages whose typings import react had no @types/react sibling. After, 0 of 88.
Ablation: drop only react-i18next's packageExtensions line

Done with scripts/ablation-replace.mjs: anchor 1 → 0, blob b5191a6c → 96febcb1. Restored to HEAD blob b5191a6c, git diff HEAD empty, lockfile restored with git checkout HEAD --.

  • Hoist-disabled install: the guard test fails (1 failed | 1 passed), and @object-ui/i18n build (forced) is back to exit 2 with the same TS2339.
  • Hoisting install (clean pnpm install --frozen-lockfile, hidden hoist present): the i18n build is GREEN (exit 0), and the guard test is RED (1 failed | 1 passed). A build or type check cannot see this regression on CI's hoisting install. The test can.
Normal hoisting install, after the fix
  • Clean pnpm install --frozen-lockfile → exit 0, which also shows the lockfile matches packageExtensions.
  • The guard test: 2/2 passed. @object-ui/i18n build --force: 5/5.
  • turbo run build:dist --filter=@objectstack/console --force (what pnpm console:build runs) → exit 0, Tasks: 77 successful, 77 total, Cached: 0 cached, 77 total.
  • pnpm --filter @object-ui/i18n type-check passed. tsc -p tsconfig.test.json --listFiles includes the new test.
  • pnpm --dir ui exec vitest run packages/i18n/ → Test Files 111 passed (111), Tests 2028 passed | 13 skipped.

Acceptance notes

  • ui/scripts/__tests__/check-lockfile-integrity.test.ts, sample (b): the peer moved the pinned snapshot key from '@ai-sdk/react@4.0.121(react@19.3.0)(zod@4.6.7)' to '@ai-sdk/react@4.0.121(@types/react@19.3.0)(react@19.3.0)(zod@4.6.7)'. The key is rebuilt to that spelling at e328e13, one string and nothing else in the file, under the seat's surface grant (claim amendment 7140294701 on console build on macOS: @object-ui/i18n fails TS2339 at packNamespace.ts:302 (I18nContext read as {}) #37015). That file plus the guard test: Test Files 2 passed (2), Tests 19 passed (19).
  • check:dual-build-cjs-loads printed PREREQUISITE NOT MET locally because this worktree has no full pnpm build. Not measured here; CI runs it.
  • Five ui packages declare no @types/react of their own (layout, plugin-dashboard, plugin-form, plugin-grid, plugin-view). They find it by walking up to ui/node_modules. Noted only; their builds pass both ways.
  • Reading useContext( across ui/packages found two third-party contexts read directly: I18nContext in packNamespace.ts, and the input-otp context in components/src/ui/input-otp.tsx. Both are covered by this fix.
  • useTranslation and I18nextProvider in provider.tsx degraded without any error before the fix: line 302 was the only i18n error. Inferred from that one error; not measured separately.
  • Long-term guard for the whole family: a check that fails when a lockfile package's typings import react without a declared or extended @types/react, or a CI leg that installs with hoist=false. It needs scripts/ plus a governed workflow, so it is not added here. Carrier: CI: no guard catches a package whose types resolve only through pnpm's hidden hoist (the #37015 Mac build failure family) #37068 (p2, lands after this PR).

Verification

First files to read, highest risk first:

  1. pnpm-workspace.yaml: the packageExtensions block and its comment.
  2. pnpm-lock.yaml: only peer suffixes and packageExtensionsChecksum should change.
  3. ui/packages/i18n/src/__tests__/react-typings-own-resolution-37015.test.ts: the confined resolver host.

Also changed: ui/scripts/__tests__/check-lockfile-integrity.test.ts, the one-string sample-key rebuild.

Two-minute check: from a clean checkout, pnpm install --frozen-lockfile --config.hoist=false --ignore-scripts && pnpm turbo run build --filter=@object-ui/i18n. Expect Tasks: 5 successful, 5 total. On origin/main the same command fails with the TS2339 above.

Gates (local subset, head 86e2b45): 41 of the 42 dispatch-gates --commands families exited 0. check:dual-build-cjs-loads printed PREREQUISITE NOT MET (exit 3). pnpm --dir ui exec vitest run scripts/ gave 171 files passed and 1 failed at 86e2b45: the lockfile-integrity sample, rebuilt at e328e13 and passing there.

https://claude.ai/code/session_01J8VVAm71aMRY4WZ9sKzkAu

🤖 Generated with Claude Code

…s import

Thirty-one packages in the lockfile ship .d.ts files that import 'react'
without declaring @types/react, so from their pnpm store directories those
types resolved only through pnpm's hidden hoist. Declare the peer through
packageExtensions so the workspace's one @types/react is linked beside each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAm71aMRY4WZ9sKzkAu
@os-zhuang

Copy link
Copy Markdown
Contributor

这个补丁是不是有点夸张,没有什么官方的升级方案吗,比如升级某个库

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · huangyiirene · session_01J8VVAjUnwjG1e7EW88ruEN

L1 review · ACCEPT

Reviewed head: e328e13f056c8b1fb4dbecfe385b1e944ef46c65
L1 thread L1-b (areas f2-D/E/F), read at 2026-11-25T00:13Z. No contract review is owed: reviewFace on the four paths finds no schema and no governed path, and the PR declares Clause-②: no with no narrowing arm. This is the seat-side self-read.

席位核对

  • 形态: l1-face.mjs --pr 37066 gives 12 ok and 1 flag (the changeset, judged below). The PR is open, draft, base main. The first content line is Fixes #37015, and no closing keyword sits next to any other card. Fixes is right against the card's own acceptance line: "the hoist-disabled Linux build passes; then the maintainer re-runs 维护者验收:在 Mac 上打包控制台并点开三个页面(#36753 收尾) #36777 on the Mac". The Mac re-run lives on 维护者验收:在 Mac 上打包控制台并点开三个页面(#36753 收尾) #36777, which stays open, and the 速读 asks for it. If the Mac still fails after the merge, that is a new card on 维护者验收:在 Mac 上打包控制台并点开三个页面(#36753 收尾) #36777's evidence, not a reopen of this one.
  • 前提实测: own probes at the head, under the repo's pnpm 10.31.0.
    • Positive control: an install from main's lockfile (no extensions) with the hidden hoist PRESENT. The new guard test went RED (1 failed | 1 passed, react-i18next finds no @types/react in its own store directory). So the guard catches the regression on a hoisting install, where a build cannot.
    • Then pnpm install --frozen-lockfile on the PR lockfile exited 0, so the lockfile matches packageExtensions. react-i18next's store directory now holds @types/react.
    • The guard test plus check-lockfile-integrity.test.ts then gave Test Files 2 passed (2), Tests 19 passed (19).
  • lockfile: normalised diff, a73edb3 against the head, with every (@types/react@19.3.0) and (@types/react-dom@19.3.0) suffix stripped (nested ones included) and the checksum line dropped. The packages: key set is equal (1691 = 1691). The snapshot base-name set is equal (1066 = 1066). There is still exactly one @types/react@19.3.0 and one @types/react-dom@19.3.0. The only residual lines are 62 '@types/react': 19.3.0 and 4 '@types/react-dom': 19.3.0 dependency entries, plus 3 transitivePeerDependencies blocks that moved. That is peer wiring only: no version moves and no new package.
  • 门禁 check-runs: at e328e13f: 59 success, 13 expected skip, 0 unexpected skip, 0 failed, 0 pending. Lint & Repo Gates success, TypeScript Type Check success, Test UI green, which covers the rebuilt lockfile-integrity sample. The dev's local ledger was at 86e2b458: 41 of 42 passed, and check:dual-build-cjs-loads was NOT MEASURED locally (exit 3, prerequisite). The CI check-runs on the head are the reading of record.
  • 接受的偏差: the claim lets pnpm-lock.yaml move "only as the regenerated consequence of a package.json change", but here it moved because of the allowed pnpm-workspace.yaml change. That is the same regenerated-consequence shape, and the PR body says so. ui/scripts/__tests__/check-lockfile-integrity.test.ts changes one string (+1/-1) under the seat's surface grant, claim amendment 7140294701, which carved it out of f2-E. The fix is a family fix (31 packages) where the card only named one, the dev said why in the body (@object-ui/components stops the build next), and the card itself asks to "cover the whole family". The PR body PATCH went through the seat, as os-dev.md requires.
  • 范围外去向: Skills-docs: not owed (kind none). The family guard (a check script or a hoist=false CI leg) is carried by CI: no guard catches a package whose types resolve only through pnpm's hidden hoist (the #37015 Mac build failure family) #37068 (p2, after this PR). Two observations with carrier: none: five ui packages reach @types/react by walking up, and the provider.tsx degradation was inferred, not measured. Both are noted only and correctly left unfiled.
  • changeset: skip-changeset is right. @object-ui/i18n ships dist, README.md, CHANGELOG.md and LICENSE, and its tsconfig excludes **/__tests__/**, so the new test does not ship. The dev's dist probe also found 0 hits for the test's symbols, against the useNamespace control's 5. The other three files are root config, the lockfile and a ui script test: none of them published. The label went on with pr_create; no command was refused.
  • 落地条款: check-governed-merges --pr 37066 reads NOT governed, 521 lines, so this is an ordinary area landing. landing-k --pr 37066 reads K = 45 ≥ 15, so merge main first (no rebase). The lockfile is the file most likely to conflict: on a conflict, regenerate it with pnpm install against the merged pnpm-workspace.yaml. Never hand-merge it. Then wait for green on the new head before arming. A clean merge, or a pure regeneration of the lockfile, keeps this verdict. Any other change to the four files comes back here.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#2 · huangyiirene · session_01J8VVAm71aMRY4WZ9sKzkAu

@os-zhuang 回复 7142687548 「这个补丁是不是有点夸张,没有什么官方的升级方案吗」:查了上游:核对过的 4 个主要库里,只有 2 个有官方升级可用,所以单靠升级库补不全这一族。

npm 实测(2026-11-25T00:44Z)

库 本仓锁定 上游从哪一版起把 @types/react 声明为可选 peer 升级代价
react-i18next 17.0.11 18.0.1(2026-11-08);17.x 全线都没有 大版本;18.x 要求 i18next >=27,本仓是 26.4.0,所以是两个大版本一起升
lucide-react 1.43.0 1.50.0 小版本
cmdk 1.1.1(已是最新) 没有 无版本可升
input-otp 1.4.2(最新 1.5.0) 没有 无版本可升

其余 27 个库在本仓锁定的版本里同样是类型文件 import 了 react 却没有声明 @types/react;它们的最新版是否已经补上,这里没有逐个核对。

为什么用 packageExtensions

  • 这是 pnpm 文档里专门用来补第三方包漏声明依赖的机制,不是绕路。
  • 声明的是 peer,不是依赖:它解析到工作区已有的 @types/react@19.3.0,不会引入第二份 React 类型。锁文件里没有任何版本移动,只多了 peer 后缀。
  • 某个库自己声明了这个 peer 之后,对应的条目就成了空操作,可以直接删掉,不留后遗症。

提议

  1. 本 PR 按现状合入,先让 Mac 上能构建控制台(维护者验收:在 Mac 上打包控制台并点开三个页面(#36753 收尾) #36777 的验收卡在这里)。
  2. 另开一张后续卡:升级 lucide-react(小版本)以及 react-i18next + i18next(大版本),升级后删掉这两个库在 packageExtensions 里的条目。

这样可以接受吗?在您回复同意(或维护者指示合入)之前,这个 PR 不会挂自动合并。


Generated by Claude Code

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-support-ai · session_01WGufzi4PechTRCTBrfxV8W

Maintainer ruling recorded · 2026-11-25T02:38Z

@os-zhuang asked (7142687548) whether an official library upgrade could replace this patch. Seat 3 checked all 31 libraries on npm. Only 7 declare @types/react in their latest release (react-i18next needs two majors, together with i18next). The other 24 never declare it, cmdk and input-otp among them, and those two are on the console build path. So an upgrade alone cannot fix #37015.

The maintainer then chose on a decision card: merge this PR as it is, and handle the upgrades on a separate card. That answers the question in 7148839083 ("这样可以接受吗?"). The owning seat (repo:objectstack#2) lands this PR on its usual path: a fresh L1 on the current head d76ab102, because the ACCEPT was at e328e13f. Seat 3 does not take it over.

The follow-up upgrade card is #37186, blocked by this PR. Each upgraded library's packageExtensions line is deleted on that card.


Generated by Claude Code

@os-zhuang
os-zhuang marked this pull request as ready for review November 25, 2026 02:39
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit ffd2a08 Nov 25, 2026
69 checks passed
@os-zhuang
os-zhuang deleted the claude/project-thread-xwd5h9 branch November 25, 2026 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file size/m skip-changeset PR has no user-facing published change; bypasses the changeset gate tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

console build on macOS: @object-ui/i18n fails TS2339 at packNamespace.ts:302 (I18nContext read as {})

3 participants