From 6b978f18bdd9fdf3ed498db624ba91a5ce3589df Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 18 Aug 2026 23:16:28 +0000 Subject: [PATCH] docs(core): fix ComponentRegistry singleton example in README packages/core/README.md's Component Registry snippet taught `new ComponentRegistry()`, but ComponentRegistry is an exported singleton instance, not a class -- packages/core/dist/registry/Registry.d.ts declares `export declare const ComponentRegistry: Registry`. The #5138 doc-snippet type gate measures this as TS2351: This expression is not constructable. README ships to npm inside the package's `files`, so a reader who copied the snippet got a compile error. Drops the `new`, calls ComponentRegistry.register/get directly on the singleton, and adds one line stating it is the process-level shared instance SchemaRenderer resolves every `type` against -- the same wording packages/components/README.md was given in #5160, kept consistent across both READMEs. Updates the UNGATED_DOCS ledger entry for packages/core/README.md in scripts/check-doc-snippet-types.mjs: TS2351x1 is dropped from the reason text now that the diagnostic is gone (measured before/after against the built dist/*.d.ts). The entry is not deleted -- the document's remaining TS2339x2 pair is a separate, pre-existing defect out of scope here, tracked as #5257. Fixes #5258 Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01RV6yuVCxymHYE16PL9vQkE --- .../core-readme-registry-singleton-5258.md | 27 +++++++++++++++++++ packages/core/README.md | 9 ++++--- scripts/check-doc-snippet-types.mjs | 2 +- 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 .changeset/core-readme-registry-singleton-5258.md diff --git a/.changeset/core-readme-registry-singleton-5258.md b/.changeset/core-readme-registry-singleton-5258.md new file mode 100644 index 000000000..8a5f5c293 --- /dev/null +++ b/.changeset/core-readme-registry-singleton-5258.md @@ -0,0 +1,27 @@ +--- +'@object-ui/core': patch +--- + +Fix `packages/core/README.md`'s Component Registry example, which taught +`new ComponentRegistry()` against an exported singleton **instance**, not a +class — the built `packages/core/dist/registry/Registry.d.ts` declares +`export declare const ComponentRegistry: Registry`, so the snippet did +not compile (`TS2351: This expression is not constructable`, measured by the +objectui#5138 doc-snippet type gate). A reader who copied it got a compile +error; if `new ComponentRegistry()` had compiled it would have produced a +second, empty registry nothing renders from, the more expensive half of the +mistake. + +The snippet now calls `ComponentRegistry.register(...)` / +`ComponentRegistry.get(...)` directly on the singleton, with one line stating +it is the process-level shared instance `SchemaRenderer` resolves every +`type` against — the same wording `packages/components/README.md` was given +in objectui#5160, kept consistent across both READMEs. Readers who want their +own isolated registry still have `Registry` itself, separately exported as a +real class. + +`scripts/check-doc-snippet-types.mjs`'s `UNGATED_DOCS` entry for +`packages/core/README.md` is updated to match: `TS2351x1` is dropped from its +reason text now that the diagnostic is gone. The entry is not deleted — the +document's remaining `TS2339x2` pair (a different, pre-existing defect) is +out of scope for this change; it's tracked as objectui#5257. diff --git a/packages/core/README.md b/packages/core/README.md index 6470f9442..807bec8ae 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -46,11 +46,14 @@ const mySchema: PageNodeSchema = { ```typescript import { ComponentRegistry } from '@object-ui/core' -const registry = new ComponentRegistry() -registry.register('button', buttonMetadata) -const metadata = registry.get('button') +ComponentRegistry.register('button', buttonMetadata) +const metadata = ComponentRegistry.get('button') ``` +`ComponentRegistry` is a process-level singleton exported by `@object-ui/core`; +`SchemaRenderer` resolves every `type` against it, so a component registered +here is renderable from schema anywhere in the app. + ### Data Scope `DataScopeManager` owns the named scopes a component tree reads from, and diff --git a/scripts/check-doc-snippet-types.mjs b/scripts/check-doc-snippet-types.mjs index ab186590b..b43e19123 100644 --- a/scripts/check-doc-snippet-types.mjs +++ b/scripts/check-doc-snippet-types.mjs @@ -246,7 +246,7 @@ const UNGATED_DOCS = { 'packages/components/README.md': '1 undefined-name diagnostic(s) — blocks continue an earlier block, or use ambient names the page never defines', 'packages/core/README.md': - '5 undefined-name diagnostic(s) — blocks continue an earlier block, or use ambient names the page never defines; plus TS2339x2 TS2351x1 — candidate real defects, un-triaged', + '5 undefined-name diagnostic(s) — blocks continue an earlier block, or use ambient names the page never defines; plus TS2339x2 — candidate real defects, un-triaged', 'packages/data-objectstack/README.md': '10 parse diagnostic(s) — blocks fenced `ts` that are bare object literals or elided bodies; 41 undefined-name diagnostic(s) — blocks continue an earlier block, or use ambient names the page never defines', 'packages/fields/README.md':