Repository navigation
fix: useDLE() types data for schema-less endpoints with nullable args - #4709
Conversation
The nullable-args overload typed data as undefined when the endpoint has no schema. Use ResolveType<E> | undefined, like useSuspense() and useCache(). Applies to React (web and native) and Vue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZEDW88C3UEjiAGULfv
🦋 Changeset detectedLatest commit: 5671c93 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Staff Reviewer: LGTM 5671c93 Validated: read the 147c308..5671c93 delta (one commit, tests only). The React and Vue useDLE tests for schema-less endpoints with nullable args now check the whole Not run locally: typecheck and tests. CI and Bugbot were still pending when I posted this. |
|
Size Change: 0 B Total Size: 97.5 kB ℹ️ View Unchanged
|
|
Docs preview: https://docs-site-pr-4709-data-client.vercel.app Built from 5671c93 merged into |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4709 +/- ##
=======================================
Coverage 98.64% 98.64%
=======================================
Files 163 163
Lines 3164 3164
Branches 629 629
=======================================
Hits 3121 3121
Misses 9 9
Partials 34 34 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Benchmark React
Details
| Benchmark suite | Current: 5671c93 | Previous: 5e42275 | Ratio |
|---|---|---|---|
data-client: getlist-100 |
374.53 ops/s (± 1.8%) |
270.97 ops/s (± 4.3%) |
0.72 |
data-client: getlist-500 |
101.06 ops/s (± 3.0%) |
73.07 ops/s (± 3.6%) |
0.72 |
data-client: update-entity |
1111.11 ops/s (± 3.3%) |
660.07 ops/s (± 1.9%) |
0.59 |
data-client: update-user |
970.87 ops/s (± 3.8%) |
583.09 ops/s (± 2.4%) |
0.60 |
data-client: getlist-500-sorted |
94.91 ops/s (± 2.4%) |
66.86 ops/s (± 3.1%) |
0.70 |
data-client: update-entity-sorted |
695.67 ops/s (± 3.1%) |
505.05 ops/s (± 2.9%) |
0.73 |
data-client: update-entity-multi-view |
814.67 ops/s (± 3.5%) |
490.2 ops/s (± 2.3%) |
0.60 |
data-client: list-detail-switch-10 |
29.48 ops/s (± 5.5%) |
8.82 ops/s (± 5.6%) |
0.30 |
data-client: update-user-10000 |
166.49 ops/s (± 2.8%) |
128.53 ops/s (± 1.2%) |
0.77 |
data-client: invalidate-and-resolve |
132.93 ops/s (± 2.3%) |
84.85 ops/s (± 2.6%) |
0.64 |
data-client: update-ticker-stream |
16.04 ops/s (± 1.2%) |
10.72 ops/s (± 1.3%) |
0.67 |
data-client: unshift-item |
608.83 ops/s (± 2.9%) |
331.68 ops/s (± 2.4%) |
0.54 |
data-client: delete-item |
813.02 ops/s (± 2.8%) |
547.2 ops/s (± 3.5%) |
0.67 |
data-client: move-item |
469.48 ops/s (± 2.7%) |
320.51 ops/s (± 2.0%) |
0.68 |
This comment was automatically generated by workflow using github-action-benchmark.
…uspenseReturn type SuspenseReturn and CondNull in react hooks/types.ts were unused and still carried the old undefined typing for schema-less nullable args. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZBtGvJe2W3ajt3TdxV
…LE tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZBtGvJe2W3ajt3TdxV
0.19.1 types useDLE()'s data for schema-less endpoints with nullable args (reactive/data-client#4709). Chess no longer has a workaround for it to remove. Claude-Session: https://claude.ai/code/session_01Y5C5ZB9HnFSLPt4AWFXpZW Co-authored-by: Claude <noreply@anthropic.com>
…lable) The "no schema -> ResolveType<E>" rule was hand-written in ~32 places and drifted twice (#4709, #4718). Export EndpointData, EndpointDataNullable and ResultEntry from normalizr (mirrored in endpoint) and use them in core, react and vue. An ESLint rule forbids new hand-written E['schema'] conditionals in core/react/vue; the few kept for annotation compatibility are listed in plans/next-breaking-release.md. Type-test matrices pin every read API to the shared types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1
…ss data (#4718) * fix: getResponse() types data for schema-less endpoints Controller and Snapshot getResponse()/getResponseMeta() typed data as undefined when the endpoint has no schema. Use ResolveType<E> | undefined, like useCache() and useDLE(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1 * internal: Format getResponse changeset example Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1 * fix: Snapshot types in endpoint and normalizr match getResponse() data SnapshotInterface (what update functions receive) still typed schema-less data as undefined. Explain the non-callable fallback and the union args in the test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1 * internal: Check both SnapshotInterface reads in getResponse test Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1 * fix: One owner for endpoint data types (EndpointData, EndpointDataNullable) The "no schema -> ResolveType<E>" rule was hand-written in ~32 places and drifted twice (#4709, #4718). Export EndpointData, EndpointDataNullable and ResultEntry from normalizr (mirrored in endpoint) and use them in core, react and vue. An ESLint rule forbids new hand-written E['schema'] conditionals in core/react/vue; the few kept for annotation compatibility are listed in plans/next-breaking-release.md. Type-test matrices pin every read API to the shared types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1 * internal: Pin fetch and useFetch endpoint data types, clearer lint message Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1 * internal: Simplify endpoint data type tests and useFetch lint exemption Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1 * internal: Clean up endpoint data lint comments and test notes Move the overload rule's reason next to its selector, correct the mirror-parity test note (only EndpointDataNullable differs for entity schemas), and drop unused NI imports in edited hooks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1 * internal: Simplify endpoint data type tests; note why fetch keeps SchemaResult Pass maybe-null args directly in the react type test, drop the vue test's alias-against-itself asserts (react's owner block covers them), and note that SchemaResult also covers plain functions with no schema member, which EndpointData does not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1 * internal: Drop endpoint data lint rule; the shared types are enough Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1 * docs: Show the getResponse() fix with an optimistic update example Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1 --------- Co-authored-by: Claude <noreply@anthropic.com>
Requested by Nathaniel · project thread
No website changes (only regenerated playground editor types).
Motivation
Bug fix.
An app calls
useDLE()with an endpoint that has noschema, and passes args that can benullto skip the fetch.In ntucker/chess,
useDLE(getEvaluation, ...(cond ? ['stockfish', line] as const : [null]))typeddataasundefined. The hook returns the resolved value at runtime, so the app could not read it without a cast.useSuspense()anduseCache()type the same call as the resolved value orundefined.Solution
The nullable-args overload of
useDLE()now typesdataasResolveType<E> | undefinedwhen the endpoint has no schema, likeuseSuspense()anduseCache(). This covers React (web and native) and Vue. No other hook overload had this mistake.Internal: deletes the unused
SuspenseReturnandCondNulltypes inpackages/react/src/hooks/types.ts. Nothing imported them, and they still had the oldundefinedtyping.Assumptions and validation
Endpointwith nullable args. They check the type (data?.titleisstring | undefined, an unknown property is an error) and the runtime value. On the old types, both tests fail typecheck withProperty 'title' does not exist on type 'never'. High certainty.useDLEReact and Vue suites pass (49 tests), with Jest's typecheck on.yarn build:types, lint and Prettier pass.yarn copy:websitetypesoutput is committed. High certainty.dataonly widens fromundefined. Code that relied onundefinedexactly would be unusual. High certainty.yarn test:coverage: no runtime code changed. Medium certainty that coverage is unchanged, since only types and tests changed.useDLE.tsfirst (moduleSuffixes: ["", ".native"]), so a native test would check the web file. It is the same one-line edit. Medium certainty.🤖 Generated with Claude Code
https://claude.ai/code/session_01Y5C5ZBtGvJe2W3ajt3TdxV
Note
Low Risk
Types-only widening of
datawith no runtime changes; risk is limited to stricter compile-time checks where code incorrectly assumeddatacould never hold a value.Overview
Fixes
useDLE()so that when an endpoint has no schema and args may benull(to skip fetching),datais typed asResolveType<E> | undefinedinstead of onlyundefined. Runtime behavior was already correct; this matchesuseSuspense()anduseCache()and lets callers use fields likedata?.titlewithout casts.The nullable-args overload is updated in React (
useDLE.ts/.native.ts) and VueuseDLE. UnusedCondNull/SuspenseReturnhelpers inpackages/react/src/hooks/types.tsare removed (nothing imported them). React and Vue tests cover schema-less endpoints with nullable args and type-check expectations.Reviewed by Cursor Bugbot for commit 5671c93. Bugbot is set up for automated code reviews on this repo. Configure here.