Repository navigation
feat(react): metadata readers can subscribe by selector — the store, per-type revisions and three hooks - #38354
Merged
Conversation
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibyRPrFte1TGnaiugba
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibyRPrFte1TGnaiugba
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibyRPrFte1TGnaiugba
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibyRPrFte1TGnaiugba
3 tasks
Contributor
Author
|
repo:objectstack#3 · os-tesla · session_01L9qibyUSf2nKJWW6qBemSU Landing · 2026-11-28T15:19Z · zone
|
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.
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 exportsMetadataStore(type),MetadataStoreCtx,useMetadataSelector,useMetadataTypeItems,useMetadataTypeStatus. Nothing is removed or renamed, and no existing hook returns anything different. The changeset shipspatchfor both packages becauseMetadata-protocolisnone(AGENTS.md Post-Task Checklist 3: "a non-protocol change, widening or breaking, shipspatch").维护者速读
useMetadataItem/useBundledItem的组件没有随数据到达而刷新;整个提交可以直接撤回。What changes
MetadataProvider(ui/packages/app-shell/src/providers/MetadataProvider.tsx) rebuilt its context value on every bump of one store-wideversioncounter, so everyuseMetadata()reader re-rendered on every bump. Re-measured on this branch's base (main a7e60c7): loading theobjectlist re-renders four memoised readers once each, though they readapps,dashboards,pages, or only holdgetItem.MetadataStoreper instance and publishes it onMetadataStoreCtx. Its state lives outside React's memo caches (ui/AGENTS.md chore: version packages #10). Everybumpnow 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 aggregateloading/errorflags 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 oldversionstill bumps, andMetadataCtxstill gets a new value per bump.@object-ui/react,AppShellContext.tsx).useMetadataSelector(select, isEqual?)runs onuseSyncExternalStore, is woken by every store commit and re-renders only when its selection changes.useMetadataTypeItems(type)anduseMetadataTypeStatus(type)subscribe only to their type (objectstatus also toview, which it waits on). Without a store (no provider, or a hand-writtenMetadataCtxvalue as most tests use), they read that value with React 19'suse()and re-render with it, so a reader under a store never subscribes toMetadataCtx.useMetadataItemreadsgetItemby selector;useMetadataTypereads its type's items and the two flags by selector;useBundledItemreads a stable copy of the bundle reads (BundledReadsStoreCtx) and is woken by#bundleand whole-store changes.useBundledReads()andbundledFirstare 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; auseMetadataSelectorreader re-renders on its selection only; a reader ofgetItemrenders once across three type loads; anisEqualkeeps a new-array selection still;useMetadataType,useMetadataItemanduseBundledItemare not re-rendered by unrelated types and are by their own answer (the bundle landing foruseBundledItem); revisions count per type; LIVE CONTROL: auseMetadata()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-rolledMetadataCtxvalue without a store is read and followed; the no-provider fallback.Ablation, on this head's source, each run against the 10 provider pins:
MetadataCtx/BundledReadsCtxwithuseContext(subscribing to the per-bump value, asmain's readers do): 8 of 10 fail (every "not re-rendered" pin; the revision pin and LIVE CONTROL stay green).bumprecords 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:
MetadataProvider.tsx,createProviderStoreand 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.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.AppShellContext.tsx,useStoreSelection: the conditionaluse(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
ui/packages/react/src/hooks/useMetadataSelector.tsand an export line inui/packages/react/src/index.ts. They live inAppShellContext.tsxbesideMetadataCtxinstead:useMetadataItem(in that file) reads throughuseMetadataSelector, and the hook's no-store fallback readsMetadataCtxand its frozen fallback, so a separate file would import that file and be imported by it.context/index.tsalready re-exports the whole file, soindex.tsneeded no line. The file surface shrank; nothing outside it was touched.@object-ui/reactminor; AGENTS.md Post-Task Checklist 3 sets the level byMetadata-protocolalone, so both packages shippatch.Human Minimum
packages/specholds no runtime logic. (not touched)pnpm lintpasses.main, one pull request.packages/spectouched: its generated artifacts are regenerated and committed. (not touched)content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.🤖 Generated with Claude Code
https://claude.ai/code/session_01L9qibyRPrFte1TGnaiugba