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

Commit c021b35

Browse files
fix(components): the react-page wrapper stops writing the host adapter under each block's dataSource (objectui#11070, round 2) (#11226)
Refs #11070 Clause-②: no, measured. Nothing under `packages/types/src` changes except one test file's prose, so the published `StrictAnyComponentSchema` and `AnyComponentSchema` are byte-identical, and M3's inputs (the three corpora and the types source) are identical between base and head. The change is in what the react-page wrapper writes onto in-memory nodes, and nothing validates those. `Refs`, not a closing keyword, on purpose. objectui#11070 stays open for the pairs this round stops at (below), the grid field's `columns`, `object-chart`'s declaration and the dashboard decision. Draft; the dev does not mark it ready. Round 2 of the card, dispatched by the `domain:devx` seat 2 on the maintainer's order, session `https://claude.ai/code/session_01TdiauJaVCHuj45EzZGUxHh`. ## What changed - **The react-page wrapper stops writing the host adapter under the node's `dataSource`.** This is the seat's answer A to round 1's `object-chart` question. `buildComponentScope` in `renderers/layout/react-page.tsx` built every injected block's node as `{ dataSource, ...props, type }`, and `Block` built its node the same way, with the adapter (or `null` before the host connects one) under `dataSource`. On a node, that key is the spec's per-element binding. Both writes are removed. The page is already wrapped in `SchemaRendererProvider dataSource={adapter}`, which is where every block resolves its adapter. An authored `dataSource={{ object: 'x' }}` still arrives on the node as written. - **The scope memo keeps its `adapter` dependency**, and the code now states the reason: the recompile on a swap re-runs page effects that read `useAdapter()` without naming it in their dependencies. Dropping the dependency would keep page state across a swap, but it would also leave such a page empty. That is a separate behaviour change and is not made here. `exhaustive-deps` now reports the dependency as unnecessary, so it carries a next-line disable with its reason, as the package's other deliberately kept dependencies do. - **Pins.** `react-page-scope.test.tsx` pins five things. The node carries no `dataSource` when the author writes none, including before the host connects an adapter. An authored binding arrives exactly as written, through the wrapper and through `Block`. The block resolves the adapter from the provider. `react-page-adapter.test.tsx` observes the adapter through the provider and asserts that no render's node carries the key. The replaced pin asserted the write, on the premise "list-view reads dataSource from props rather than from context". That premise is false: `ListViewBlock` takes `props.dataSource`, which `SchemaRenderer` strips, and otherwise the context. The five cross-file line citations in `react-page-scope.test.tsx` are rewritten by content (AGENTS.md rule 11). - **`strict-face-read-keys-11070.test.ts`: assertions unchanged.** The `object-chart.dataSource` case still asserts the refusal, but its title no longer gives the write as the reason. The pending-list comment now records why `return_type` / `summary_type` wait. - **Changeset:** `.changeset/11070-react-page-no-adapter-on-node.md`, `@object-ui/components` **patch**. Why patch: no declared or documented surface moves (types, exports, docs), and every registered renderer measured the same (census below). The one observable difference is a host component that read the adapter off `schema.dataSource` inside a react page, and the body names its replacement. ## Who consumed the write: a census A scratch instrument, never committed, rendered every registered type through the real `SchemaRenderer`. It covered 483 types: the console's registrations, plus every lazily registered plugin imported eagerly. Each type rendered once with a recording adapter under the node and a separate one in `SchemaRendererProvider`, and once without the node key. The instrument compared adapter method calls and settled markup, with generated ids normalised. - **Positive control.** A stand-in that reads `schema.dataSource` and calls `find` was reported, so a real consumer would be. - **Types that call a method on the node's adapter:** `user` and `field:user` only (`getObjectSchema`). They reach it through `LookupField`'s resolution chain, `props.dataSource ?? lookupField?.dataSource ?? fieldMeta?.dataSource ?? context`, in which the node is the field carrier. Without the key, they call the provider's adapter. In a react page that is the same object. - **47 types touch the node value only to ask whether it has `find`.** That is `isElementDataSourceConfig`, the gate's check that tells a binding from an adapter. - **Settled markup is identical for all 483 types.** Adapter call sets are identical too, except that the `user` pair moves from the node to the provider. For the 47 blocks the react-page scope injects, the `null` window (no adapter yet) was also compared both ways: identical. - **`object-chart` stands on its own.** With no write, `{ dataSource: { object: 'account' }, aggregate, chartType }` drives `aggregate('account')` and `getObjectSchema('account')` through the provider's adapter, the same as the `objectName` control. A node with neither key makes no call. - **What the write cost, on the built dist.** On each of the seven blocks that declare the binding, `safeValidateSchema` refuses a node that carries `dataSource: null` or an adapter, at `dataSource`. The same node without the key is not refused there. The consumers exist, but none depends on finding the adapter on the node, and the non-authorable channel already exists. So the write is removed, not rerouted. ## Stopped at the declaration boundary The dispatch's rule: a pair that needs a `packages/types` declaration stops, the rest is finished, and the stop is reported. 1. **`fields[].return_type` and `fields[].summary_type`: no change.** The seat's answer A is that the widgets read the spec spellings. The widgets' reads are as the card says: `FormulaField` reads `formulaField?.return_type || 'text'`, and `SummaryField` reads `summaryField?.summary_type || 'count'`. But the form-field face declares neither spec spelling. On a form field, the shipped strict face refuses `returnType` and `summaryOperations` by name (`unrecognized_keys`), just as it refuses the snake keys, while the declared control `reference` passes. Moving the reads and the fixtures now would only rename the refused key. It would also leave `FormulaFieldMetadata.return_type` and `SummaryFieldMetadata.summary_type` (`field-types.ts`) declared and unread. The move needs `form.ts` and `zod/form.zod.ts` (the latter is held by objectui#6152 round 3), plus `field-types.ts`. 2. **`content/docs/fields/lookup.mdx` and `password.mdx`: the premise is false as stated, and the pages are unchanged.** Their TypeScript fences annotate `LookupFieldMetadata` and `PasswordFieldMetadata` (`field-types.ts`), and those types declare `reference_to` and `min_length` / `max_length`. Round 1 declared `reference` / `minLength` on `FormField`, which is a different type. I measured it: with `reference` / `minLength` in those fences, `check:doc-snippets` goes red with two TS2561 errors, and the checker's message suggests the snake spelling. Correcting the pages first needs those types moved to the spec spellings. The trial edits went through `ablation-replace` and were restored, proven by the blob matching HEAD and `git diff HEAD` being empty. ## M3, before and after The method ports PR #11069's M3: the corpus loaders and schema-guided node walk from `scripts/measure-strict-authoring-face.mjs`, plus #11069's `findUndeclaredKeys` (ported verbatim from `a11f73347`). It runs over the shipped `StrictAnyComponentSchema` in a freshly built `packages/types/dist`, and attributes each refused key to its owning node by object identity along the refused path. It is a scratch script and is never committed. | reading | base `52bf348` | head `77fc4e9` | | --- | --: | --: | | node documents | 599 | 599 | | refused by the strict face | 97 | 97 | | of them strict-only | 61 | 61 | | refused by the tolerant face | 36 | 36 | | **class (ii)** pairs / occurrences / strict-only | **12 / 53 / 53** | **12 / 53 / 53** | The head column was run. The base column follows from the inputs: `git diff --quiet` over the three corpora and the types source (tests excluded) answers 0 between the two commits, and the control, a path this branch changes, answers 1. Class (ii) is exactly the card's remaining list. It is the 9 dashboard pairs, with 44 occurrences (`options.data` 12, `options.xField` 11, `options.yField` 11, `options.value` 5, and `options.description`, `options.trend`, `component.chartType`, `component.series`, `component.xAxisKey` at 1 each), plus `return_type` 3, `summary_type` 3 and `columns` 3. Round 1 read 12 / 38 / 38. The extra 15 occurrences come from catalog `plugin-dashboard/filtered-dashboard-*` fixtures on this base. The corpus grew; this shallow checkout cannot date when. **Class (ii) does not shrink this round,** contrary to the dispatch's H3. `return_type` / `summary_type` stopped at the boundary. The docs pairs are not M3 pairs, because M3's docs corpus is its `json` fences and those were TypeScript fences. And no corpus document writes `object-chart.dataSource`. ## Tests and gates All at head `77fc4e9` unless marked. Each exit code was captured before any pipe. | gate | exit | verdict | | --- | --: | --- | | `pnpm --filter @object-ui/components --filter @object-ui/types run type-check` | 0 | both `type-check: Done`; `--listFiles` shows all three changed tests inside the test programs | | `pnpm exec vitest run packages/components/` | 0 | `Test Files 341 passed / 1 skipped (342)`, `Tests 3372 passed / 24 skipped` | | `pnpm exec vitest run packages/types/` | 0 | `Test Files 289 passed (289)`, `Tests 6882 passed (6882)` | | the 13 test files outside those two packages that render a `kind:'react'` page or name the wrapper (`apps/console` 4, `core` 3, `layout`, `plugin-charts` 2, `plugin-list`, `react-runtime`, `sdui-parser`), found by grepping tests for `kind: 'react'` / `ReactKindPage` / `buildComponentScope` / `react-page` | 0 | `Test Files 13 passed (13)`, `Tests 255 passed (255)` | | `pnpm check:doc-snippets` (closure built at `a5a9a68`; from there to head, the components source changes by one comment line) | 0 | `696 of 696 block(s) judged, 0 failed` | | `check:doc-fences`, `docs:check-links`, `check:control-bytes`, `check:test-path-roots` | 0 | OK | | `check:new-line-citations` | 0 | `0 new citation(s)` | | `check:changeset-claims`, `check:pending-changeset-literals` | 0 | report-only. The four pending changesets that name `react-page.tsx` were read; none states the write | | `node scripts/check-changeset-presence.mjs` | 0 | declares `.changeset/11070-react-page-no-adapter-on-node.md` | | eslint on the four changed files (JSON) | 0 | 0 errors. Warnings per file equal base (6 / 11 / 3 / 0), measured by linting the base blobs through `--stdin` | - **`@object-ui/fields` type-check and test: not run.** This round changes nothing under `packages/fields`. - **NOT MEASURED:** the repository-wide lint and the test shards outside the sets above. Both are CI's runs. ### Reverse verification Both ablations went through objectstack's `scripts/ablation-replace.mjs`: the anchor hit once, the blob moved, and the restore left the blob equal to HEAD with `git diff HEAD` empty. The prediction was written before each run, and the subject is imported from source. | ablation | predicted | measured | | --- | --- | --- | | A1: the wrapper's node gets `dataSource: null` again | 3 red: flat props, the `null` window, the adapter swap | 3 failed / 12 passed, those three | | A2: the `Block` node gets `dataSource: null` again | 1 red: the `Block` case | 1 failed / 14 passed, that one | ## Acceptance notes - **`object-chart`'s declaration is the next round.** It needs `packages/types/src/zod/**` and the objectui#10770 pin. That pin's `SHOWCASE_NODE` still carries `dataSource: null`, now models a node the wrapper no longer builds, and stays green. - **`LookupField`'s chain takes `lookupField?.dataSource` as an adapter.** On a `lookup` / `user` node rendered through `Block`, an authored binding under that key would be taken as an adapter. Not measured; no document writes one. - **New pairs beside class (ii) at this base.** On `action:button`, `actionType` (7), `icon` (4), `variant` (2), and `endpoint`, `method` and `target` (1 each), all in docs fences. They teach the flat node spelling, which the objectui#10872 batch-4 arm moved into `properties`. AGENTS.md rule 4's own example node is refused the same way on the strict face. These are objectui#10872's open flat-spelling question; they are not graded here. - **The dashboard analysis is in this round's report** on objectui#11070. Nothing in this PR touches the dashboard pairs. --- _Generated by [Claude Code](https://claude.ai/code/session_01TdiauJaVCHuj45EzZGUxHh)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent dded788 commit c021b35

5 files changed

Lines changed: 149 additions & 45 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
'@object-ui/components': patch
3+
---
4+
5+
fix(components): a `kind:'react'` page no longer writes the host adapter under each block's `dataSource`
6+
7+
The react-page wrapper built every injected block's node (and every `<Block>`
8+
node) as `{ dataSource, ...props, type }`, with the host's data-source ADAPTER,
9+
or `null` before one connects, under `dataSource`. On a node that key is
10+
`@objectstack/spec`'s per-element BINDING (`PageComponentSchema.dataSource`,
11+
`{ object, view, filter, sort, limit }`), so the wrapper wrote an adapter into
12+
an authored key. Such an in-memory node was refused by `safeValidateSchema` on
13+
every block that declares the binding. That also kept `object-chart` from
14+
declaring it.
15+
16+
The node now carries only what the author wrote. The adapter still reaches every
17+
block through the `SchemaRendererProvider` the page is wrapped in, the channel
18+
each registered block already resolves it from. `SchemaRenderer` never spread
19+
the node's `dataSource` as a React prop, and the gate ignores a value that is not
20+
a binding. The one widget family that looked for an adapter on its own node
21+
(the `lookup` / `user` field widgets, reached through `<Block>`) falls through
22+
to that same provider. An author's `dataSource={{ object: 'x' }}` arrives on the
23+
node as written, as before.
24+
25+
Who notices: a host-registered component, rendered inside a react page, that
26+
read the adapter off `schema.dataSource`. It gets the node's authored binding,
27+
or nothing, and should read the adapter from the schema renderer context
28+
(`SchemaRendererContext`), as it must everywhere outside react pages.

‎packages/components/src/__tests__/react-page-adapter.test.tsx‎

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,35 @@
88
* The adapter reaches a `kind:'react'` page's blocks, and keeps reaching them
99
* when the host swaps it.
1010
*
11-
* `ReactKindPage` memoises the injected scope on `[schema, adapter]`, and that
12-
* `adapter` dependency looks like something to optimise away — it is the one
13-
* remaining thing that can recompile the page and cost its `useState`
14-
* (objectui#2954). It cannot go.
11+
* The blocks resolve it from the `SchemaRendererProvider` the page is wrapped
12+
* in — the channel every registered block reads. It is NOT stamped onto the
13+
* node: `dataSource` there is the spec's per-element binding, and the wrapper
14+
* used to pun the adapter (or `null`) into it (objectui#11070). The stand-in
15+
* below therefore reads the context, as the real blocks do, and asserts the
16+
* node carries no `dataSource` at all.
1517
*
16-
* `ReactRunner` returns the SAME element object while `(code, scope)` are
17-
* unchanged, and React bails out of re-rendering a child whose element is
18-
* referentially identical. So the page subtree does not re-render on its own:
19-
* recompiling is the ONLY way a new adapter reaches the blocks inside the page.
20-
* Drop the dependency (or read the adapter through a ref to "keep the scope
21-
* stable") and every block in every react page silently keeps querying through
22-
* the dead adapter — no error, just stale or failing data.
18+
* `ReactKindPage` memoises the injected scope on `[schema, adapter]`, and a
19+
* change to either recompiles the page and costs its `useState`
20+
* (objectui#2954). The `adapter` half now serves the page's OWN code, not the
21+
* blocks (see the comment on that memo): an effect that reads through
22+
* `useAdapter()` without naming the adapter in its dependencies is re-run by
23+
* that recompile.
2324
*
24-
* These pin both halves so the tradeoff cannot be quietly re-litigated:
25-
* a swapped adapter must reach the blocks, and an unchanged one must not
26-
* disturb them.
25+
* These pin both halves: a swapped adapter must reach the blocks, and an
26+
* unchanged one must not disturb the page.
2727
*/
2828

2929
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
3030
import { render, waitFor } from '@testing-library/react';
3131
import React from 'react';
3232
import { ComponentRegistry } from '@object-ui/core';
33-
import { SchemaRenderer, AdapterCtx } from '@object-ui/react';
33+
import { SchemaRenderer, AdapterCtx, SchemaRendererContext } from '@object-ui/react';
3434
import '../renderers';
3535

36-
/** The dataSource each render of the stand-in block was handed. */
36+
/** The adapter each render of the stand-in block resolved from its context. */
3737
const seen: unknown[] = [];
38+
/** Whether each render's node carried a `dataSource` key. */
39+
const nodeCarriedDataSource: boolean[] = [];
3840

3941
const makeAdapter = (id: string) => ({ id, find: async () => [] }) as any;
4042

@@ -58,7 +60,8 @@ const SCHEMA = { type: 'home', kind: 'react', name: 'adapter_page', source: SOUR
5860
// See object-ui/no-dynamic-import-in-test-hook (objectui#3010/#3021).
5961
beforeAll(() => {
6062
ComponentRegistry.register('list-view', (props: any) => {
61-
seen.push(props.schema?.dataSource);
63+
seen.push(React.useContext(SchemaRendererContext)?.dataSource);
64+
nodeCarriedDataSource.push(!!props.schema && 'dataSource' in props.schema);
6265
return <div data-testid="list-view-double" />;
6366
});
6467
});
@@ -78,6 +81,7 @@ function Host({ adapter }: { adapter: any }) {
7881
describe('kind:\'react\' page ↔ adapter identity', () => {
7982
it('hands blocks the new adapter when the host swaps it', async () => {
8083
seen.length = 0;
84+
nodeCarriedDataSource.length = 0;
8185
const first = makeAdapter('first');
8286
const second = makeAdapter('second');
8387

@@ -87,11 +91,10 @@ describe('kind:\'react\' page ↔ adapter identity', () => {
8791

8892
rerender(<Host adapter={second} />);
8993

90-
// Nothing else re-renders the page subtree — ReactRunner hands React the
91-
// same element object while (code, scope) hold, and React bails out on an
92-
// identical element reference. Recompiling on the new scope is what carries
93-
// the adapter in.
94+
// The block reads the provider, so the new adapter reaches it through
95+
// context propagation; the node carries none on any render.
9496
await waitFor(() => expect(seen.at(-1)).toBe(second));
97+
expect(nodeCarriedDataSource).not.toContain(true);
9598
});
9699

97100
it('leaves the page alone while the adapter identity holds', async () => {

‎packages/components/src/__tests__/react-page-scope.test.tsx‎

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
* These tests pin the four halves of that contract:
2020
* 1. `list-view` / `object-form` stay eligible for injection;
2121
* 2. an author writes `<ListView …/>` with FLAT props and no import, and the
22-
* wrapper folds them into the block's `schema`;
22+
* wrapper folds them into the block's `schema` — whose `dataSource` is the
23+
* author's binding and never the host adapter (2b, objectui#11070);
2324
* 3. a block that is only *lazily* registered is in the scope too — the
2425
* contract may not depend on which plugin chunks happen to be loaded
2526
* (objectui#2953);
@@ -35,18 +36,18 @@ import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest';
3536
import { render, waitFor } from '@testing-library/react';
3637
import React from 'react';
3738
import { ComponentRegistry } from '@object-ui/core';
38-
import { SchemaRenderer, AdapterCtx } from '@object-ui/react';
39+
import { SchemaRenderer, AdapterCtx, SchemaRendererContext } from '@object-ui/react';
3940
// Registers PageRenderer for `type:'home'`, which dispatches kind:'react'.
4041
import '../renderers';
4142

4243
/** Props the stand-in blocks last received, for flat-prop assertions. */
43-
const captured: { listView?: any; objectForm?: any; kanban?: any } = {};
44+
const captured: { listView?: any; listViewContextAdapter?: unknown; objectForm?: any; kanban?: any } = {};
4445

4546
const adapter = { find: async () => [], getObjectSchema: async () => ({ name: 'showcase_project', fields: {} }) } as any;
4647

47-
function renderReactPage(source: string) {
48+
function renderReactPage(source: string, hostAdapter: typeof adapter | null = adapter) {
4849
return render(
49-
<AdapterCtx.Provider value={adapter}>
50+
<AdapterCtx.Provider value={hostAdapter}>
5051
<SchemaRenderer schema={{ type: 'home', kind: 'react', name: 'test_page', source }} />
5152
</AdapterCtx.Provider>,
5253
);
@@ -64,6 +65,9 @@ beforeAll(() => {
6465
// @object-ui/components, so nothing is being clobbered.
6566
ComponentRegistry.register('list-view', (props: any) => {
6667
captured.listView = props;
68+
// The adapter a block resolves when its node carries none: the page's
69+
// provider, the channel every registered block reads (objectui#11070).
70+
captured.listViewContextAdapter = React.useContext(SchemaRendererContext)?.dataSource;
6771
return <div data-testid="list-view-double" />;
6872
});
6973
ComponentRegistry.register('object-form', (props: any) => {
@@ -79,6 +83,7 @@ afterAll(() => {
7983

8084
beforeEach(() => {
8185
captured.listView = undefined;
86+
captured.listViewContextAdapter = undefined;
8287
captured.objectForm = undefined;
8388
captured.kanban = undefined;
8489
});
@@ -93,7 +98,8 @@ describe('kind:\'react\' scope eligibility', () => {
9398
(tag) => {
9499
const cfg = ComponentRegistry.getPublicConfigs().find((c: any) => c.type === tag);
95100
// Missing from PUBLIC_BLOCKS, or marked isContainer, => dropped from the
96-
// scope of every kind:'react' page (react-page.tsx:64-66).
101+
// scope of every kind:'react' page (the `cfg.isContainer` skip in
102+
// `buildComponentScope`).
97103
expect(cfg).toBeTruthy();
98104
expect((cfg as any).isContainer).toBeFalsy();
99105
},
@@ -120,7 +126,7 @@ function Page() {
120126
expect(await findByTestId('list-view-double')).toBeTruthy();
121127
expect(await findByTestId('object-form-double')).toBeTruthy();
122128
// The failure mode this guards: `ReferenceError: ListView is not defined`
123-
// surfaced through ReactRunner's fallback (react-page.tsx:186-191).
129+
// surfaced through the `fallback` `ReactKindPage` hands `ReactRunner`.
124130
expect(queryByText('React page error')).toBeNull();
125131
});
126132

@@ -133,7 +139,7 @@ function Page() {
133139
await findByTestId('list-view-double');
134140

135141
// Flat JSX props are folded into the schema bag, and the discriminator wins
136-
// the `type` slot (react-page.tsx:79-84).
142+
// the `type` slot (the wrapper's `specType` stamp in `buildComponentScope`).
137143
expect(captured.listView.schema).toMatchObject({
138144
type: 'list-view',
139145
objectName: 'showcase_project',
@@ -143,9 +149,11 @@ function Page() {
143149
// Callbacks must survive as real props — the master/detail pattern in
144150
// apps/console/src/sdui-workbench-preview.tsx is built on onRowClick.
145151
expect(typeof captured.listView.onRowClick).toBe('function');
146-
// The wrapper stamps the live adapter in, since list-view reads dataSource
147-
// from props rather than from context (react-page.tsx:61-63).
148-
expect(captured.listView.schema.dataSource).toBe(adapter);
152+
// The adapter is NOT stamped onto the node (objectui#11070). `dataSource` on
153+
// a node is the spec's per-element binding; the adapter reaches the block
154+
// through the `SchemaRendererProvider` the page is wrapped in.
155+
expect('dataSource' in captured.listView.schema).toBe(false);
156+
expect(captured.listViewContextAdapter).toBe(adapter);
149157
});
150158

151159
it('injects useAdapter so a page can query on its own', async () => {
@@ -159,6 +167,48 @@ function Page() {
159167
});
160168
});
161169

170+
// ---------------------------------------------------------------------------
171+
// 2b. `dataSource` on the node is the author's binding, and only that
172+
// (objectui#11070)
173+
// ---------------------------------------------------------------------------
174+
175+
describe('kind:\'react\' page — the node\'s `dataSource` is the authored binding', () => {
176+
it('carries a binding the author writes, exactly as written', async () => {
177+
const source = `
178+
function Page() {
179+
return <ListView dataSource={{ object: 'showcase_project', limit: 5 }} />;
180+
}`;
181+
const { findByTestId } = renderReactPage(source);
182+
await findByTestId('list-view-double');
183+
expect(captured.listView.schema.dataSource).toEqual({ object: 'showcase_project', limit: 5 });
184+
expect(captured.listViewContextAdapter).toBe(adapter);
185+
});
186+
187+
it('writes nothing under `dataSource` through the `Block` escape hatch either', async () => {
188+
const source = `
189+
function Page() {
190+
return <Block type="list-view" objectName="showcase_project" />;
191+
}`;
192+
const { findByTestId } = renderReactPage(source);
193+
await findByTestId('list-view-double');
194+
expect(captured.listView.schema).toMatchObject({ type: 'list-view', objectName: 'showcase_project' });
195+
expect('dataSource' in captured.listView.schema).toBe(false);
196+
});
197+
198+
it('writes no `dataSource: null` before the host connects an adapter', async () => {
199+
// The window objectui#7912 names: `useAdapter()` answers `null`. That
200+
// absence is the provider's value; the node states nothing about it.
201+
const source = `
202+
function Page() {
203+
return <ListView objectName="showcase_project" />;
204+
}`;
205+
const { findByTestId } = renderReactPage(source, null);
206+
await findByTestId('list-view-double');
207+
expect('dataSource' in captured.listView.schema).toBe(false);
208+
expect(captured.listViewContextAdapter).toBeNull();
209+
});
210+
});
211+
162212
// ---------------------------------------------------------------------------
163213
// 3. Lazily-registered blocks are contract members too (objectui#2953)
164214
// ---------------------------------------------------------------------------
@@ -273,7 +323,7 @@ function Page() {
273323
// Proves the assertions above are meaningful: when a block really is absent
274324
// from scope, the author sees this.
275325
//
276-
// The panel is ReactRunner's own `fallback` (react-page.tsx:186-191).
326+
// The panel is the `fallback` `ReactKindPage` hands `ReactRunner`.
277327
// Pinning it also pins objectui#2954: `getDerivedStateFromProps` used to
278328
// re-transpile on every render and reset `error: null`, so the recovery
279329
// render rebuilt the same throwing element and the error escaped PAST this

‎packages/components/src/renderers/layout/react-page.tsx‎

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,23 @@ function toPascal(tag: string): string {
7070
// to SchemaRenderer, which triggers the loader and renders the placeholder, so
7171
// the scope itself never has to change once built — which is exactly what lets
7272
// it stay identity-stable and keeps the page from remounting (objectui#2954).
73-
function buildComponentScope(dataSource: unknown): Record<string, React.ComponentType<any>> {
73+
//
74+
// The host ADAPTER reaches the blocks through ONE channel: the
75+
// `SchemaRendererProvider` the page is wrapped in below. It is NOT written onto
76+
// the node. `dataSource` on a node is the spec's per-element BINDING
77+
// (`PageComponentSchema.dataSource`, `{ object, view, filter, sort, limit }`),
78+
// which the gate-wrapped blocks read off `schema` (`ElementDataSourceGate`), so
79+
// an adapter (or `null`) stamped there was a pun on an authored key
80+
// (objectui#11070). It carried nothing the provider does not: `SchemaRenderer`
81+
// strips `dataSource` from the props it spreads, the gate ignores a value that
82+
// is not a binding, and the one widget family that looks for an adapter on its
83+
// node (`LookupField`, and `UserField` through it, reached by `<Block>`) falls
84+
// through to that same context. An author who writes
85+
// `dataSource={{ object: 'x' }}` on a block gets exactly that binding on the
86+
// node.
87+
function buildComponentScope(): Record<string, React.ComponentType<any>> {
7488
const scope: Record<string, React.ComponentType<any>> = {};
7589
const seen = new Set<string>();
76-
// Some data blocks read their dataSource from props (e.g. `list-view`), others
77-
// from the SchemaRenderer context (e.g. `object-form`). We inject it as a prop
78-
// here AND wrap the page in a SchemaRendererProvider below, so both kinds work.
7990
for (const cfg of ComponentRegistry.getPublicConfigs() as Array<{ type: string; isContainer?: boolean; tier?: string }>) {
8091
const tag = cfg.type;
8192
// The html tier's intrinsic elements ride `getPublicConfigs()` stamped
@@ -100,15 +111,15 @@ function buildComponentScope(dataSource: unknown): Record<string, React.Componen
100111
const Wrapper: React.FC<any> = ({ children: _children, ...props }) => {
101112
const specType = typeof props.type === 'string' && props.type !== tag ? props.type : undefined;
102113
return React.createElement(SchemaRenderer as any, {
103-
schema: { dataSource, ...props, ...(specType ? { specType } : {}), type: tag },
114+
schema: { ...props, ...(specType ? { specType } : {}), type: tag },
104115
});
105116
};
106117
Wrapper.displayName = name;
107118
scope[name] = Wrapper;
108119
}
109120
// Escape hatch: render any registered component by type.
110121
const Block: React.FC<{ type: string; [k: string]: unknown }> = ({ type, children: _c, ...props }) =>
111-
React.createElement(SchemaRenderer as any, { schema: { type, dataSource, ...props } });
122+
React.createElement(SchemaRenderer as any, { schema: { type, ...props } });
112123
Block.displayName = 'Block';
113124
scope.Block = Block;
114125
return scope;
@@ -183,9 +194,18 @@ export const ReactKindPage: React.FC<{ schema: any }> = ({ schema }) => {
183194
// plugin finishing its registration notifies the registry, and rebuilding the
184195
// scope there would reset every interactive page on the screen. It doesn't
185196
// need to — `buildComponentScope` already sees lazy blocks (objectui#2953).
197+
//
198+
// `adapter` stays in the dependency list although the scope no longer
199+
// carries it (objectui#11070). The blocks follow a swapped adapter through the
200+
// provider below without a recompile. The page's OWN code may not: an effect
201+
// that reads through `useAdapter()` and omits `adapter` from its dependencies
202+
// ran once, against the absent adapter, and the recompile on a swap (the
203+
// host connecting one) is what re-runs it. Dropping the dependency would keep
204+
// the page's state across a swap, but it would also leave such a page empty.
205+
// That is a separate behaviour change, not made here.
186206
const scope = React.useMemo(
187207
() => ({
188-
...buildComponentScope(adapter),
208+
...buildComponentScope(),
189209
// Live data access — `const adapter = useAdapter()` inside the page, then
190210
// adapter.find('object', {...}) / .create / .update. Hooks injected as
191211
// closure vars; the page calls them from its own component body.
@@ -202,6 +222,7 @@ export const ReactKindPage: React.FC<{ schema: any }> = ({ schema }) => {
202222
variables: schema?.variables ?? {},
203223
page: schema ?? {},
204224
}),
225+
// eslint-disable-next-line react-hooks/exhaustive-deps -- `adapter` is a recompile trigger kept on purpose, not a read; the reason is above this memo.
205226
[schema, adapter],
206227
);
207228

0 commit comments

Comments
 (0)