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

Commit 28be078

Browse files
os-teslaobjectui-agentclaude
authored
fix(skills): guard the DataSource read in the marked data-integration example (#9352)
The marked fence under "Via DataSource methods (in plugin code)" destructured `dataSource` from `useSchemaContext()` and called `.find()` on it with no guard. `useSchemaContext()` throws only when there is no PROVIDER; a provider with no adapter bound is an ordinary, supported state (a Studio preview, a page that renders before the host connects its adapter, a widget test that drives `apiFetch` alone), so the published guidance, copied into a plugin on such a surface, throws at the first call. Add the guard and move the prose with it, so a reader comes away knowing WHY the adapter can be absent rather than reading the line as gate appeasement. The `os:check` marker stays: the example is meant to compile, and dropping the marker would retire the coverage while leaving the same unguarded pattern published for readers to copy. Claude-Session: https://claude.ai/code/session_01UzHd6hDYatoDn17BuwKxnZ Co-authored-by: objectui-agent <yinlianghui@steedos.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2e471dc commit 28be078

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎skills/objectui/guides/data-integration.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,15 @@ different envelope and behaves differently; see
291291

292292
### Via DataSource methods (in plugin code)
293293

294-
Plugin components that need CRUD operations access the DataSource from context:
294+
Plugin components that need CRUD operations access the DataSource from context
295+
— and must guard it before calling. `useSchemaContext()` throws only when there
296+
is **no provider** above the component; a provider with **no adapter bound** is
297+
an ordinary, supported state (a Studio preview, a page that renders before the
298+
host connects its adapter, a widget test that drives `apiFetch` alone). The
299+
renderer itself already reads the member that way — `useDataScope` returns
300+
`undefined` when nothing is bound — so an unguarded call throws on its first use
301+
in exactly those places. Decide what the component shows while the adapter is
302+
absent (objectui#7912):
295303

296304
<!-- os:check -->
297305
```typescript
@@ -301,6 +309,9 @@ function MyPlugin() {
301309
const { dataSource } = useSchemaContext();
302310

303311
const loadData = async () => {
312+
// No adapter bound is a real state, not an error — see above.
313+
if (!dataSource) return [];
314+
304315
const result = await dataSource.find('contacts', {
305316
$filter: { active: true },
306317
$orderby: [{ field: 'name', order: 'asc' }],

0 commit comments

Comments
 (0)