Skip to content

feat(react): metadata readers can subscribe by selector — the store, per-type revisions and three hooks - #38354

Merged
objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/project-thread-5fgm7s
Nov 28, 2026
Merged

objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/project-thread-5fgm7s

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Tesla · project thread

Part of #37903

This is PR 1 of 3 on the card (claim 7235141537, route A): the base readers subscribe through. It migrates no reader family; PR 2 (the shell) and PR 3 (the list and record pages, with the #37444 readings) do, each after its own claim amendment. useMetadata() keeps its behaviour in every PR of this card.

Clause-②: yes (widening)
Metadata-protocol: none

Widening (public API of @object-ui/react): new exports MetadataStore (type), MetadataStoreCtx, useMetadataSelector, useMetadataTypeItems, useMetadataTypeStatus. Nothing is removed or renamed, and no existing hook returns anything different. The changeset ships patch for both packages because Metadata-protocol is none (AGENTS.md Post-Task Checklist 3: "a non-protocol change, widening or breaking, ships patch").

维护者速读

  • 控制台里读元数据的组件,以后可以只在自己读的那一类元数据变化时才重新渲染,不再每次有任何元数据到达就全部重绘。这一片只铺底座,用户看到的页面和速度暂时不变。
  • 属于「控制台首屏 2.5 秒内打开」专题(专题:控制台首屏 2.5 秒内打开(首页、对象列表、记录页) #38082)。后面两片把外壳、列表页和记录页的读者改过来,那时首屏才会变快。
  • 出错的话,最可能是某个读 useMetadataItem / useBundledItem 的组件没有随数据到达而刷新;整个提交可以直接撤回。
  • 无

What changes

MetadataProvider (ui/packages/app-shell/src/providers/MetadataProvider.tsx) rebuilt its context value on every bump of one store-wide version counter, so every useMetadata() reader re-rendered on every bump. Re-measured on this branch's base (main a7e60c7): loading the object list re-renders four memoised readers once each, though they read apps, dashboards, pages, or only hold getItem.

  1. The store. The provider creates one MetadataStore per instance and publishes it on MetadataStoreCtx. Its state lives outside React's memo caches (ui/AGENTS.md chore: version packages #10). Every bump now names what changed: a type's list landing, failing or being invalidated names that type; an object-scope answer names #scope; the app bundle names #bundle; a preview or organization switch, a new adapter, or a bump that names nothing (the safe default) changes the whole store. The aggregate loading / error flags are recorded as #status. After each provider commit a layout effect counts a revision per changed key and wakes the readers subscribed to it, so a reader always selects from the value that commit rendered. The old version still bumps, and MetadataCtx still gets a new value per bump.
  2. The hooks (@object-ui/react, AppShellContext.tsx). useMetadataSelector(select, isEqual?) runs on useSyncExternalStore, is woken by every store commit and re-renders only when its selection changes. useMetadataTypeItems(type) and useMetadataTypeStatus(type) subscribe only to their type (object status also to view, which it waits on). Without a store (no provider, or a hand-written MetadataCtx value as most tests use), they read that value with React 19's use() and re-render with it, so a reader under a store never subscribes to MetadataCtx.
  3. Three hooks read through it. useMetadataItem reads getItem by selector; useMetadataType reads its type's items and the two flags by selector; useBundledItem reads a stable copy of the bundle reads (BundledReadsStoreCtx) and is woken by #bundle and whole-store changes. useBundledReads() and bundledFirst are unchanged.

Why

The card's lever (#37903, from PR #37883's profile): six store bumps before a list page's first paint each re-render every metadata reader. A reader can only stop doing that once it has something narrower to subscribe to; this PR is that something.

Tests

  • app-shell/src/providers/__tests__/MetadataProvider.selectorStore-37903.test.tsx (10 pins, a real provider over a served adapter): a per-type reader is not re-rendered by another type landing and is by its own list changing; a status reader likewise; a useMetadataSelector reader re-renders on its selection only; a reader of getItem renders once across three type loads; an isEqual keeps a new-array selection still; useMetadataType, useMetadataItem and useBundledItem are not re-rendered by unrelated types and are by their own answer (the bundle landing for useBundledItem); revisions count per type; LIVE CONTROL: a useMetadata() reader still re-renders on every change.
  • app-shell/src/providers/__tests__/metadataRenderCount.harness.tsx: the render-count harness PR 2 and PR 3 pin their reader families with (memoised counted readers, a served adapter, an app-bundle double).
  • react/src/context/__tests__/useMetadataSelector-37903.test.tsx (5 pins, a hand-written store): each hook subscribes with the types it reads; selection and per-type wake-ups; a hand-rolled MetadataCtx value without a store is read and followed; the no-provider fallback.

Ablation, on this head's source, each run against the 10 provider pins:

  • A: the hooks also read MetadataCtx / BundledReadsCtx with useContext (subscribing to the per-bump value, as main's readers do): 8 of 10 fail (every "not re-rendered" pin; the revision pin and LIVE CONTROL stay green).
  • B: bump records no type names (the store never learns what changed): 6 of 10 fail (every "re-renders with its own type" pin and the revision pin).

Verification

Read first, by risk:

  1. MetadataProvider.tsx, createProviderStore and the layout effect after the context value: the flush must run after the commit that rendered the change, and be keyed on state, not on the memoised value.
  2. The bump(...) call sites: each names exactly what it changed, or nothing. A site that names too little leaves a per-type reader stale; the default with no names is the whole store.
  3. AppShellContext.tsx, useStoreSelection: the conditional use(MetadataCtx) only when no store is published.

Two-minute check: pnpm --dir ui exec vitest run packages/app-shell/src/providers/__tests__/MetadataProvider.selectorStore-37903.test.tsx packages/react/src/context/__tests__/useMetadataSelector-37903.test.tsx. All 15 should pass.

Acceptance notes

  • The claim placed the hooks in a new ui/packages/react/src/hooks/useMetadataSelector.ts and an export line in ui/packages/react/src/index.ts. They live in AppShellContext.tsx beside MetadataCtx instead: useMetadataItem (in that file) reads through useMetadataSelector, and the hook's no-store fallback reads MetadataCtx and its frozen fallback, so a separate file would import that file and be imported by it. context/index.ts already re-exports the whole file, so index.ts needed no line. The file surface shrank; nothing outside it was touched.
  • The claim named @object-ui/react minor; AGENTS.md Post-Task Checklist 3 sets the level by Metadata-protocol alone, so both packages ship patch.

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic. (not touched)
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint passes.
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: its generated artifacts are regenerated and committed. (not touched)
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English.
  • The Before Submitting list in CONTRIBUTING.md is done.

🤖 Generated with Claude Code

https://claude.ai/code/session_01L9qibyRPrFte1TGnaiugba

@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 28, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-tesla · session_01L9qibyUSf2nKJWW6qBemSU

Landing · 2026-11-28T15:19Z · zone o3-ux (seat card thread) · PR 1 of 3 on #37903 (Part of #37903; the card stays dispatched)
Head-sha: e6c912cca40c2cc2fa2d666b7416d26b76469499

  • L1-a ACCEPT 7241349703 at this head. No isolated L2: no spec, governed or narrowing face on the 7 files; the Clause-② yes (widening) face is covered by the TIER_DEFAULT record PASS 7241335796 at this head.
  • Both claim deviations accepted by L1: the hooks live in AppShellContext.tsx (import cycle), and patch changesets (a none-kind widening ships patch). Nits N1 (store value set in render) and N2 (separator assumption) carry to PR 2/3.
  • check-governed-merges.mjs --pr 38354: NOT governed. Size +953 / −29; the card's running total stays under the human-review line, and PRs 2 and 3 count toward it.
  • K: 13 < 15.
  • Checks at this head: 45 success, 13 skipped, 0 failed. mergeable_state clean.
  • Action: mark ready for review and enable auto-merge (queue).

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 28, 2026 15:20
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit ce51400 Nov 28, 2026
59 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-5fgm7s branch November 28, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants