Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit edea22a

Browse files
os-teslaclaudeos-tesla
authored
fix(react)!: dataSource at the renderer seam is the published DataSource contract (#9310)
* fix(react)!: dataSource at the renderer seam is the published DataSource contract `SchemaRendererProvider`'s `dataSource` prop and the context type every `useSchemaContext()` consumer reads back were both declared `any`, so a bare string passed where the host's adapter belongs raised nothing at compile time and failed at runtime on the first `find()`. Both are now `DataSource | null | undefined` — the spelling `useSettledSchema` in this same package already used — so the two absences that really occur stay expressible and everything that is not an adapter is refused. Red call sites are repaired by typing, never by casting at the seam: - `useClientNotifications` declares `getClient` as the adapter CAPABILITY it is and probes it with a type guard, instead of reaching through `any`. - `useDataScope`'s path walk annotates its accumulator; its published return type is unchanged. - `ObjectGallery` drops a hand-rolled `{ find }` stand-in for the real contract, and the now-redundant cast at its `useSettledSchema` call. - the `kind:'react'` page stops passing a truthy empty object as its "no adapter yet" stand-in, so the `if (!dataSource)` guards written for that state fire; the memo identity the module constant existed for is kept, because the absent adapter is itself render-stable. - calendar, gantt and kanban collapse a null context adapter to the single spelling their widget prop declares. - five redundant `as any` reads of this context in `@object-ui/fields` are gone, along with `LookupField`'s local re-declaration of the imported context as a `Context` of `any`, which laundered its `dataSource` read while looking typed. Test doubles keep every injected value byte-for-byte and mark the crossing, so no assertion moves: a double that stubs only the members its path calls is not a host, and completing them would change which capability probes fire. Both directions are pinned against the real compiler, with controls that fire if the harness ever stops resolving the real types. The documentation probe from the card — a bare string in this package's README provider example — now fails `check:doc-snippets`, where it used to exit 0 with zero diagnostics; the same gate caught the quick-start guide teaching an empty object, which is repaired. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UzHd6hDYatoDn17BuwKxnZ * fix(site): the live demo has no adapter to inject, and now says so CI's "Build Docs" job caught the one injection site the type-check union in the previous commit did not cover: `apps/site` was excluded from that filter, and `LiveSplitDemo` handed the provider a truthy empty object as its "no adapter" stand-in — the same shape already corrected in the `kind:'react'` page. Every preset this component renders is a static schema; the object-bound examples live in `InteractiveDemo` and `SchemaThumbnail`, which inject the docs gallery adapter. So this surface has no adapter, and `undefined` is what that is. Still a module constant, because the memo below keys on its identity. The union is corrected with it: dropping `--filter='!@object-ui/site'` puts the site's own `type-check` back in scope, which is where this would have surfaced locally. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UzHd6hDYatoDn17BuwKxnZ * test(components): mark the guide's data-scope injection as the crossing it is `Type Check` went red on this branch only after `main` merged in: objectui#8021's `guide-schema-rendering-data-context-8021.test.tsx` injects a plain scope bag as `SchemaRendererProvider.dataSource`, and legs A/C/D exist to measure exactly that — the renderer binds the context's `dataSource` as the expression `data` root. The file landed after this branch's own sweep, so it is the one injection site the sweep could not have marked. Same treatment as the other 33 test files here: an explicit `as unknown as DataSource` at the injection, with the file's own note naming the second meaning. The injected value is byte-for-byte what it was, all six assertions are unchanged, and the declaration is untouched — nothing widens, nothing is skipped. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UzHd6hDYatoDn17BuwKxnZ --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: os-tesla <yinlianghui@steedos.com>
1 parent 5a41ce7 commit edea22a

52 files changed

Lines changed: 1043 additions & 111 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
'@object-ui/react': minor
3+
'@object-ui/components': minor
4+
'@object-ui/fields': minor
5+
'@object-ui/plugin-list': minor
6+
'@object-ui/plugin-calendar': minor
7+
'@object-ui/plugin-gantt': minor
8+
'@object-ui/plugin-kanban': minor
9+
'@object-ui/plugin-charts': minor
10+
'@object-ui/plugin-dashboard': minor
11+
'@object-ui/plugin-detail': minor
12+
---
13+
14+
**BREAKING** — `SchemaRendererProvider`'s `dataSource` prop, and the context
15+
type every `useSchemaContext()` consumer reads back, are the published
16+
`DataSource` contract instead of `any`.
17+
18+
**FROM** `dataSource={anything}` **TO** `dataSource={adapter}` — a `DataSource`
19+
from `@object-ui/types`, or `null` / `undefined` when the host has no adapter
20+
bound.
21+
22+
```ts
23+
// before — compiled, and failed at runtime on the first find()
24+
<SchemaRendererProvider dataSource={'not-an-adapter'}>
25+
// before — compiled, and no reader can do anything with it
26+
<SchemaRendererProvider dataSource={{}}>
27+
// after
28+
<SchemaRendererProvider dataSource={adapter}> // a DataSource
29+
<SchemaRendererProvider dataSource={undefined}> // "I have no adapter"
30+
```
31+
32+
Both sites are typed `DataSource | null | undefined` — the spelling
33+
`useSettledSchema` in this same package already used. The two absences are part
34+
of the contract, not a weakening of it: a Studio preview, a `kind:'react'` page
35+
rendered before the host's adapter connects, and a widget probe driving
36+
`apiFetch` alone all render with nothing bound, and every reader in the tree
37+
already guards for it. What the union refuses is everything that is not an
38+
adapter: a string, an empty object, a plain data bag, a partial adapter missing
39+
a required member.
40+
41+
The measured cost, both halves, because the two `any`s have different blast
42+
radii (measured separately on `origin/main`, whole-repo type-check over the 33
43+
packages that depend on `@object-ui/react`):
44+
45+
- the **context type** — the `any` that reaches every `useSchemaContext()`
46+
reader — reds **7 diagnostics at 7 sites in 4 packages**, all of them
47+
production code or a mocked module factory.
48+
- the **provider prop** — the injection points — reds **52 diagnostics at 27
49+
sites in 11 packages**, all but one of them test doubles.
50+
51+
That ordering is the reverse of the prediction on the card: the context `any`
52+
was expected to be the expensive one because it infects the whole tree, and it
53+
is the cheap one, because every reader in the tree already guarded and none of
54+
them ever reached past `find` / `getObjectSchema`. The prop is the expensive
55+
one, because the injection points are overwhelmingly test doubles that were
56+
never complete adapters. The full accounting is on objectui#7912.
57+
58+
Two runtime behaviours change, both in the "no adapter" direction and both
59+
strictly closer to what the surrounding code already intended:
60+
61+
- `@object-ui/components`' `kind:'react'` page passed an empty object as its
62+
"no adapter yet" stand-in. An empty object is TRUTHY, so it walked past every
63+
`if (!dataSource)` guard written to catch exactly that state and failed later,
64+
at the call. It now passes the absent adapter itself, so the guard fires where
65+
it was meant to. The module-constant identity that stand-in existed for is
66+
preserved: `null` is a primitive, so the provider's memo is unaffected.
67+
- `@object-ui/plugin-calendar`, `@object-ui/plugin-gantt` and
68+
`@object-ui/plugin-kanban` collapse a `null` adapter from the context to
69+
`undefined` before handing it to their widget, whose prop declares the single
70+
spelling `dataSource?: DataSource`.
71+
72+
Nothing else moves at runtime: no value flowing through this key changes, and
73+
no data path is touched. A TypeScript consumer outside this repo that handed
74+
this prop something other than an adapter now gets a compile error naming the
75+
key (TS2322 / TS2739 / TS2740), which is why the FROM/TO is spelled out above.
76+
77+
Five `as any` reads of this context in `@object-ui/fields` are gone — they were
78+
redundant the moment the seam became honest — and `LookupField`'s local
79+
re-declaration of the imported context as a `Context` of `any`, which laundered
80+
its `dataSource` read while looking typed, is gone with them. Both directions of
81+
the contract are pinned against the real compiler in
82+
`SchemaRendererContext.dataSourceType.pin.test.ts`, and the card's planted
83+
documentation probe (a bare string in `packages/react/README.md`'s provider
84+
example) now fails `pnpm check:doc-snippets`, where it used to exit 0 with zero
85+
diagnostics.
86+
87+
objectui#7912.

‎apps/site/app/components/LiveSplitDemo.tsx‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,19 @@ const PRESET_LABELS: Record<(typeof PRESET_IDS)[number], string> = {
4343
'components-complex-table/basic-table': 'Table',
4444
};
4545

46-
const defaultCtx = { dataSource: {} };
46+
/**
47+
* The provider value these demos render under. Every preset in `PRESET_IDS` is
48+
* a STATIC schema — the object-bound examples live in `InteractiveDemo` /
49+
* `SchemaThumbnail`, which inject `galleryDataSource` — so this surface has no
50+
* adapter to hand over and says so with `undefined` (objectui#7912).
51+
*
52+
* It used to say `{}`. An empty object is TRUTHY, so it walked past the
53+
* `if (!dataSource)` guard every reader writes for exactly this state; the seam
54+
* now declares `DataSource | null | undefined`, so the absence is stated rather
55+
* than smuggled. Still a module constant, for the same reason as before: the
56+
* memo below keys on its identity, and `undefined` is render-stable.
57+
*/
58+
const defaultCtx = { dataSource: undefined };
4759

4860
class PreviewErrorBoundary extends Component<
4961
{ children: ReactNode; signal: unknown },

‎content/docs/guide/quick-start.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const schema: CardSchema = {
109109
function App() {
110110
return (
111111
<div className="min-h-screen bg-background p-8 text-foreground">
112-
<SchemaRendererProvider dataSource={{}}>
112+
<SchemaRendererProvider dataSource={undefined}>
113113
<SchemaRenderer schema={schema} />
114114
</SchemaRendererProvider>
115115
</div>
@@ -119,7 +119,9 @@ function App() {
119119
export default App;
120120
```
121121

122-
Importing `@object-ui/components` and `@object-ui/fields` registers their renderers with the shared `ComponentRegistry`. `SchemaRendererProvider` supplies the data scope used by expressions, smart fields, and data-aware plugins.
122+
Importing `@object-ui/components` and `@object-ui/fields` registers their renderers with the shared `ComponentRegistry`. `SchemaRendererProvider` injects the host's data adapter, and everything below it — expressions, smart fields, data-aware plugins — reads it back from there.
123+
124+
This app renders inline `data`, so it has no adapter to inject and says so with `undefined`. That is a real state of the contract, not a placeholder: `dataSource` is typed `DataSource | null | undefined` (`@object-ui/types`), so a host either hands over an adapter or states that it has none. It used to be typed `any` and this example passed an empty object, which no renderer can do anything with (objectui#7912).
123125

124126
## Step 5: Run the App
125127

@@ -134,7 +136,7 @@ Open [http://localhost:5173](http://localhost:5173). You should see a card and d
134136
1. **Schema** - the UI was described as JSON with `type`, visual props, and nested `body`.
135137
2. **Registry** - importing the component packages registered renderers for `card` and `data-table`.
136138
3. **Renderer** - `SchemaRenderer` resolved each `type` and rendered React components.
137-
4. **Provider** - `SchemaRendererProvider` made a data scope available for expressions and plugins.
139+
4. **Provider** - `SchemaRendererProvider` is where a host injects its `DataSource`; this app has none, so it passes `undefined`.
138140

139141
## Next Steps
140142

‎packages/components/src/__tests__/bindable-text-keys-4795.test.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,25 @@ import { SchemaRenderer, SchemaRendererProvider } from '@object-ui/react';
3737
// Module scope, not a hook — the cold transform would otherwise be billed to
3838
// `hookTimeout` (object-ui/no-dynamic-import-in-test-hook, objectui#3010).
3939
import '../renderers';
40+
import type { DataSource } from '@object-ui/types';
41+
42+
/**
43+
* NOTE (objectui#7912): `SchemaRendererProvider.dataSource` — and the context
44+
* it feeds — declare the published `DataSource` adapter contract. The values
45+
* this file injects are deliberately NOT adapters —
46+
* they are the `data` ROOT of the expression scope — the renderer binds
47+
* `SchemaRendererContext.dataSource` as `data` for every predicate, which is
48+
* the second meaning this one key carries.
49+
* Each injection therefore crosses the contract with an explicit
50+
* `as unknown as DataSource`. Every injected value is byte-for-byte what it
51+
* was before: this marks the crossing, it changes no assertion.
52+
*/
4053

4154
const DATA = { total: 99, caption: 'Active users', note: '+20.1% from last month' };
4255

4356
const renderNode = (schema: any) =>
4457
render(
45-
<SchemaRendererProvider dataSource={DATA}>
58+
<SchemaRendererProvider dataSource={DATA as unknown as DataSource}>
4659
<SchemaRenderer schema={schema} />
4760
</SchemaRendererProvider>,
4861
);

‎packages/components/src/__tests__/data-table-node-data-diagnostic.test.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,22 @@ import { SchemaRenderer, SchemaRendererProvider } from '@object-ui/react';
5151
// self-import (`scripts/check-package-self-import.mjs`).
5252
import '../renderers';
5353
import {
54+
55+
/**
56+
* NOTE (objectui#7912): `SchemaRendererProvider.dataSource` — and the context
57+
* it feeds — declare the published `DataSource` adapter contract. The values
58+
* this file injects are deliberately NOT adapters —
59+
* they are the `data` ROOT of the expression scope — the renderer binds
60+
* `SchemaRendererContext.dataSource` as `data` for every predicate, which is
61+
* the second meaning this one key carries.
62+
* Each injection therefore crosses the contract with an explicit
63+
* `as unknown as DataSource`. Every injected value is byte-for-byte what it
64+
* was before: this marks the crossing, it changes no assertion.
65+
*/
5466
DATA_TABLE_BIND_DIAGNOSTIC_PREFIX,
5567
DATA_TABLE_DATA_DIAGNOSTIC_PREFIX,
5668
} from '../renderers/complex/dataTableBindDiagnostic';
69+
import type { DataSource } from '@object-ui/types';
5770

5871
/** Identical in every leg, so the only variable is where `data` was written. */
5972
const COLUMNS = [
@@ -101,7 +114,7 @@ function warningsOn(prefix: string): string[] {
101114

102115
function tree(schema: unknown) {
103116
return (
104-
<SchemaRendererProvider dataSource={SCOPE}>
117+
<SchemaRendererProvider dataSource={SCOPE as unknown as DataSource}>
105118
<SchemaRenderer schema={schema as never} />
106119
</SchemaRendererProvider>
107120
);

‎packages/components/src/__tests__/guide-schema-rendering-data-context-8021.test.tsx‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ import { dirname, join, resolve } from 'node:path';
6666
import { fileURLToPath } from 'node:url';
6767
import '../renderers';
6868
import { SchemaRenderer, SchemaRendererProvider } from '@object-ui/react';
69+
import type { DataSource } from '@object-ui/types';
70+
71+
/**
72+
* NOTE (objectui#7912): `SchemaRendererProvider.dataSource` — and the context
73+
* it feeds — declare the published `DataSource` adapter contract. The values
74+
* this file injects are deliberately NOT adapters —
75+
* `SCOPE` is the `data` ROOT of the expression scope, which is exactly what
76+
* this document's Data Context passage teaches and what legs A/C/D measure:
77+
* the renderer binds `SchemaRendererContext.dataSource` as `data` for every
78+
* predicate, the second meaning this one key carries (objectui#9308).
79+
* Each injection therefore crosses the contract with an explicit
80+
* `as unknown as DataSource`. Every injected value is byte-for-byte what it
81+
* was before: this marks the crossing, it changes no assertion.
82+
*/
6983

7084
/**
7185
* Anchored on this file's own naked `import.meta.url`, never on
@@ -108,7 +122,7 @@ function renderWithDataProp(content: string): string {
108122
function renderWithProvider(content: string): string {
109123
return (
110124
render(
111-
<SchemaRendererProvider dataSource={SCOPE}>
125+
<SchemaRendererProvider dataSource={SCOPE as unknown as DataSource}>
112126
<SchemaRenderer schema={textNode(content)} />
113127
</SchemaRendererProvider>,
114128
).container.textContent ?? ''

‎packages/components/src/__tests__/skill-guide-data-table-binding.test.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ import { SchemaRenderer, SchemaRendererProvider } from '@object-ui/react';
7575
// package self-import (`scripts/check-package-self-import.mjs`).
7676
import '../renderers';
7777
import { DATA_TABLE_BIND_DIAGNOSTIC_PREFIX } from '../renderers/complex/dataTableBindDiagnostic';
78+
import type { DataSource } from '@object-ui/types';
79+
80+
/**
81+
* NOTE (objectui#7912): `SchemaRendererProvider.dataSource` — and the context
82+
* it feeds — declare the published `DataSource` adapter contract. The values
83+
* this file injects are deliberately NOT adapters —
84+
* they are the `data` ROOT of the expression scope — the renderer binds
85+
* `SchemaRendererContext.dataSource` as `data` for every predicate, which is
86+
* the second meaning this one key carries.
87+
* Each injection therefore crosses the contract with an explicit
88+
* `as unknown as DataSource`. Every injected value is byte-for-byte what it
89+
* was before: this marks the crossing, it changes no assertion.
90+
*/
7891

7992
const here = path.dirname(fileURLToPath(import.meta.url));
8093
const repoRoot = path.resolve(here, '../../../..');
@@ -152,7 +165,7 @@ function bindWarnings(): string[] {
152165

153166
function renderNode(schema: unknown, dataSource: unknown) {
154167
return render(
155-
<SchemaRendererProvider dataSource={dataSource}>
168+
<SchemaRendererProvider dataSource={dataSource as unknown as DataSource}>
156169
<SchemaRenderer schema={schema as never} />
157170
</SchemaRendererProvider>,
158171
);

‎packages/components/src/__tests__/skill-guide-provider-envelope.test.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ import { SchemaRenderer, SchemaRendererProvider } from '@object-ui/react';
6565
// specifier: this file lives inside `@object-ui/components`
6666
// (`scripts/check-package-self-import.mjs`).
6767
import '../renderers';
68+
import type { DataSource } from '@object-ui/types';
69+
70+
/**
71+
* NOTE (objectui#7912): `SchemaRendererProvider.dataSource` — and the context
72+
* it feeds — declare the published `DataSource` adapter contract. The values
73+
* this file injects are deliberately NOT adapters —
74+
* they are the `data` ROOT of the expression scope — the renderer binds
75+
* `SchemaRendererContext.dataSource` as `data` for every predicate, which is
76+
* the second meaning this one key carries.
77+
* Each injection therefore crosses the contract with an explicit
78+
* `as unknown as DataSource`. Every injected value is byte-for-byte what it
79+
* was before: this marks the crossing, it changes no assertion.
80+
*/
6881

6982
const here = path.dirname(fileURLToPath(import.meta.url));
7083
const repoRoot = path.resolve(here, '../../../..');
@@ -90,7 +103,7 @@ const EMPTY_STATE = 'No results foundTry adjusting your filters or search query.
90103

91104
function renderNode(schema: unknown) {
92105
return render(
93-
<SchemaRendererProvider dataSource={PROVIDER}>
106+
<SchemaRendererProvider dataSource={PROVIDER as unknown as DataSource}>
94107
<SchemaRenderer schema={schema as never} />
95108
</SchemaRendererProvider>,
96109
);

‎packages/components/src/renderers/__tests__/shadowed-renderer-behaviour.test.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ import { SchemaRenderer, SchemaRendererProvider } from '@object-ui/react';
3232
// Module-scope side-effect import, not a `beforeAll` — see
3333
// object-ui/no-dynamic-import-in-test-hook (objectui#3010/#3021).
3434
import '../index';
35+
import type { DataSource } from '@object-ui/types';
36+
37+
/**
38+
* NOTE (objectui#7912): `SchemaRendererProvider.dataSource` — and the context
39+
* it feeds — declare the published `DataSource` adapter contract. The values
40+
* this file injects are deliberately NOT adapters —
41+
* they are the `data` ROOT of the expression scope — the renderer binds
42+
* `SchemaRendererContext.dataSource` as `data` for every predicate, which is
43+
* the second meaning this one key carries.
44+
* Each injection therefore crosses the contract with an explicit
45+
* `as unknown as DataSource`. Every injected value is byte-for-byte what it
46+
* was before: this marks the crossing, it changes no assertion.
47+
*/
3548

3649
const PEOPLE = [
3750
{ name: 'Ada', role: 'Engineer' },
@@ -59,7 +72,7 @@ const DATA_SOURCE = {
5972

6073
const renderBound = (schema: Record<string, unknown>) =>
6174
render(
62-
<SchemaRendererProvider dataSource={DATA_SOURCE}>
75+
<SchemaRendererProvider dataSource={DATA_SOURCE as unknown as DataSource}>
6376
<SchemaRenderer schema={schema as never} />
6477
</SchemaRendererProvider>,
6578
);

‎packages/components/src/renderers/action/__tests__/action-enablement-cel-envelope.test.tsx‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ import { SchemaRenderer, SchemaRendererProvider, PredicateScopeProvider } from '
5858
// the import phase, not under a hook timeout.
5959
import '../action-button';
6060
import '../action-icon';
61+
import type { DataSource } from '@object-ui/types';
62+
63+
/**
64+
* NOTE (objectui#7912): `SchemaRendererProvider.dataSource` — and the context
65+
* it feeds — declare the published `DataSource` adapter contract. The values
66+
* this file injects are deliberately NOT adapters —
67+
* they are the `data` ROOT of the expression scope — the renderer binds
68+
* `SchemaRendererContext.dataSource` as `data` for every predicate, which is
69+
* the second meaning this one key carries.
70+
* Each injection therefore crosses the contract with an explicit
71+
* `as unknown as DataSource`. Every injected value is byte-for-byte what it
72+
* was before: this marks the crossing, it changes no assertion.
73+
*/
6174

6275
const DATA = { status: 'draft' };
6376

@@ -67,7 +80,7 @@ const FAILS = { dialect: 'cel', source: 'has(data.status) && data.status == "pub
6780

6881
function mountAction(type: 'action:button' | 'action:icon', properties: Record<string, unknown>) {
6982
return render(
70-
<SchemaRendererProvider dataSource={DATA}>
83+
<SchemaRendererProvider dataSource={DATA as unknown as DataSource}>
7184
<PredicateScopeProvider scope={{ data: DATA }}>
7285
<SchemaRenderer
7386
schema={

0 commit comments

Comments
 (0)