Repository navigation
fix: One owner for endpoint data types; getResponse() types schema-less data - #4718
Conversation
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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1
🦋 Changeset detectedLatest commit: 7b4539a The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 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+FOLLOW_UP ef30f69 Type-only fix that brings Update for 3de41f9 (Snapshot types in endpoint and normalizr): good catch. FOLLOW_UP (after merge): the rule "no schema → Verified by reading the diff since baae39f, the new compile-time test, and that |
|
Size Change: 0 B Total Size: 97.5 kB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Benchmark React
Details
| Benchmark suite | Current: 7b4539a | Previous: 9b1a4a1 | Ratio |
|---|---|---|---|
data-client: getlist-100 |
271.55 ops/s (± 3.4%) |
373.85 ops/s (± 3.0%) |
1.38 |
data-client: getlist-500 |
75.77 ops/s (± 2.5%) |
97.92 ops/s (± 2.9%) |
1.29 |
data-client: update-entity |
694.44 ops/s (± 1.6%) |
980.39 ops/s (± 1.8%) |
1.41 |
data-client: update-user |
609.76 ops/s (± 2.7%) |
1066.73 ops/s (± 4.6%) |
1.75 |
data-client: getlist-500-sorted |
68.8 ops/s (± 3.2%) |
78.76 ops/s (± 8.2%) |
1.14 |
data-client: update-entity-sorted |
454.55 ops/s (± 1.3%) |
630.91 ops/s (± 2.1%) |
1.39 |
data-client: update-entity-multi-view |
497.51 ops/s (± 2.0%) |
715.62 ops/s (± 1.7%) |
1.44 |
data-client: list-detail-switch-10 |
11.27 ops/s (± 8.9%) |
19.75 ops/s (± 9.9%) |
1.75 |
data-client: update-user-10000 |
131.62 ops/s (± 2.4%) |
191.94 ops/s (± 2.0%) |
1.46 |
data-client: invalidate-and-resolve |
86.21 ops/s (± 2.1%) |
117.37 ops/s (± 2.9%) |
1.36 |
data-client: update-ticker-stream |
10.15 ops/s (± 2.0%) |
13.15 ops/s (± 2.8%) |
1.30 |
data-client: unshift-item |
357.14 ops/s (± 1.8%) |
507.61 ops/s (± 2.0%) |
1.42 |
data-client: delete-item |
498.75 ops/s (± 2.2%) |
781.25 ops/s (± 2.4%) |
1.57 |
data-client: move-item |
318.98 ops/s (± 2.2%) |
483.09 ops/s (± 1.8%) |
1.51 |
This comment was automatically generated by workflow using github-action-benchmark.
|
Docs preview: https://docs-site-pr-4718-data-client.vercel.app Built from 7b4539a merged into |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4718 +/- ##
=======================================
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.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit baae39f. Configure here.
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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1
There was a problem hiding this comment.
Benchmark
Details
| Benchmark suite | Current: 7b4539a | Previous: efeb593 | Ratio |
|---|---|---|---|
normalizeLong |
669 ops/sec (±0.13%) |
476 ops/sec (±0.45%) |
0.71 |
normalizeLong Values |
603 ops/sec (±0.11%) |
428 ops/sec (±0.59%) |
0.71 |
normalizeLong Scalar |
571 ops/sec (±2.06%) |
405 ops/sec (±3.49%) |
0.71 |
normalizeLong Scalar update |
1135 ops/sec (±0.85%) |
859 ops/sec (±1.02%) |
0.76 |
denormalizeLong |
418 ops/sec (±5.92%) |
283 ops/sec (±7.71%) |
0.68 |
denormalizeLong Values |
390 ops/sec (±4.05%) |
272 ops/sec (±4.76%) |
0.70 |
denormalizeLong donotcache |
1534 ops/sec (±0.28%) |
1186 ops/sec (±0.72%) |
0.77 |
denormalizeLong nested 25% missing |
478 ops/sec (±4.38%) |
322 ops/sec (±5.73%) |
0.67 |
denormalizeLong nested 25% null |
483 ops/sec (±4.09%) |
329 ops/sec (±4.83%) |
0.68 |
denormalizeLong nested 25% INVALID |
486 ops/sec (±4.02%) |
346 ops/sec (±4.66%) |
0.71 |
denormalizeLong Values donotcache |
1082 ops/sec (±0.16%) |
821 ops/sec (±0.26%) |
0.76 |
denormalizeLong Scalar donotcache |
1528 ops/sec (±0.17%) |
1127 ops/sec (±0.48%) |
0.74 |
denormalizeShort donotcache 500x |
2232 ops/sec (±0.12%) |
1646 ops/sec (±1.10%) |
0.74 |
denormalizeShort 500x |
1126 ops/sec (±5.30%) |
719 ops/sec (±7.10%) |
0.64 |
denormalizeShort 500x withCache |
11219 ops/sec (±0.27%) |
8466 ops/sec (±0.54%) |
0.75 |
queryShort 500x withCache |
5743 ops/sec (±0.17%) |
3910 ops/sec (±1.21%) |
0.68 |
buildQueryKey All |
83594 ops/sec (±0.28%) |
65056 ops/sec (±0.57%) |
0.78 |
query All withCache |
7788 ops/sec (±5.00%) |
6973 ops/sec (±4.58%) |
0.90 |
denormalizeLong with mixin Entity |
399 ops/sec (±5.55%) |
271 ops/sec (±7.31%) |
0.68 |
denormalizeLong withCache |
11388 ops/sec (±0.19%) |
9172 ops/sec (±0.22%) |
0.81 |
denormalizeLong withCache (Scalar churn) |
11339 ops/sec (±0.18%) |
8901 ops/sec (±4.44%) |
0.78 |
denormalizeLong nested 25% missing withCache |
9892 ops/sec (±0.18%) |
7671 ops/sec (±0.27%) |
0.78 |
denormalizeLong nested 25% null withCache |
10031 ops/sec (±0.17%) |
8221 ops/sec (±0.31%) |
0.82 |
denormalizeLong nested 25% INVALID withCache |
8139 ops/sec (±0.14%) |
7938 ops/sec (±0.21%) |
0.98 |
denormalizeLong Values withCache |
5427 ops/sec (±0.12%) |
4705 ops/sec (±0.55%) |
0.87 |
denormalizeLong Scalar withCache |
6605 ops/sec (±0.24%) |
6010 ops/sec (±0.47%) |
0.91 |
denormalizeLong Scalar update withCache |
3238 ops/sec (±0.12%) |
2784 ops/sec (±0.44%) |
0.86 |
denormalizeLong All withCache |
6285 ops/sec (±0.23%) |
5837 ops/sec (±0.26%) |
0.93 |
denormalizeLong Query-sorted withCache |
8410 ops/sec (±4.76%) |
7405 ops/sec (±5.64%) |
0.88 |
denormalizeLongAndShort withEntityCacheOnly |
1687 ops/sec (±0.14%) |
1688 ops/sec (±0.43%) |
1.00 |
denormalize bidirectional 50 |
7578 ops/sec (±8.78%) |
5287 ops/sec (±11.18%) |
0.70 |
denormalize bidirectional 50 donotcache |
63982 ops/sec (±0.26%) |
50149 ops/sec (±1.01%) |
0.78 |
getResponse |
5372 ops/sec (±4.55%) |
4795 ops/sec (±5.68%) |
0.89 |
getResponse (null) |
17185075 ops/sec (±0.41%) |
13190515 ops/sec (±0.59%) |
0.77 |
getResponse (clear cache) |
363 ops/sec (±7.58%) |
231 ops/sec (±8.56%) |
0.64 |
getSmallResponse |
6374 ops/sec (±0.19%) |
4562 ops/sec (±0.41%) |
0.72 |
getSmallInferredResponse |
5155 ops/sec (±0.32%) |
3597 ops/sec (±4.13%) |
0.70 |
getResponse Collection |
5316 ops/sec (±3.97%) |
4292 ops/sec (±4.67%) |
0.81 |
get Collection |
2706 ops/sec (±0.18%) |
2139 ops/sec (±0.44%) |
0.79 |
get Query-sorted |
5902 ops/sec (±3.26%) |
5359 ops/sec (±1.88%) |
0.91 |
setLong |
667 ops/sec (±0.17%) |
499 ops/sec (±0.45%) |
0.75 |
setLongWithMerge |
356 ops/sec (±0.20%) |
277 ops/sec (±0.40%) |
0.78 |
setLongWithSimpleMerge |
384 ops/sec (±0.32%) |
289 ops/sec (±0.64%) |
0.75 |
setSmallResponse 500x |
1535 ops/sec (±0.13%) |
993 ops/sec (±1.29%) |
0.65 |
setMany 50x one-per-row |
265 ops/sec (±0.27%) |
255 ops/sec (±1.15%) |
0.96 |
setMany 50 batch |
6079 ops/sec (±0.19%) |
4424 ops/sec (±4.59%) |
0.73 |
setMany 500x one-per-row |
27.16 ops/sec (±0.37%) |
29.14 ops/sec (±0.80%) |
1.07 |
setMany 500 batch |
1846 ops/sec (±1.23%) |
1438 ops/sec (±0.59%) |
0.78 |
This comment was automatically generated by workflow using github-action-benchmark.
…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
|
Staff Reviewer: LGTM 7b4539a Update for a50db27 (one owner for endpoint data types): this resolves my earlier FOLLOW_UP inside the PR, and it does it the right way.
No open follow-ups from Staff. The remaining type cleanups are tracked in What I checked: I read the diff from ef30f69 to a50db27, how the normalizr index re-exports the new types, how the rest and core indexes use |
…ssage Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1
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
…emaResult 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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1
0.19.2 types getResponse() data for endpoints without a schema (reactive/data-client#4718), so useFinder no longer casts the explorer counts, and the Maia shares branch is typed instead of undefined. Claude-Session: https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1 Co-authored-by: Claude <noreply@anthropic.com>

Requested by Nathaniel · project thread
Motivation
Bug fix.
An app reads an endpoint that has no
schemawithController.getResponse()orgetResponseMeta(), or with a snapshot (including thesnapan update function such asgetOptimisticResponse()receives). TypeScript typesdataasundefined, becauseDenormalizeNullable<undefined>isundefined. The value at runtime is the stored response.One instance: a chess app reads cached lichess explorer counts with
ctrl.getResponse(getExplorerCounts, band, key, state).data. It must castdatatoExplorerCounts | undefinedto use it.This is the second bug of its kind after #4709 (
useDLE()). The rule "no schema → what the function resolves to" was written out by hand in about 32 places across core, endpoint, normalizr, rest, react and vue. Each bug was one copy that drifted.Solution
EndpointData<E>,EndpointDataNullable<E>andResultEntry<E>own the rule. They are defined in normalizr, and endpoint keeps its usual mirror copy so mixed package versions still work.useSuspense(),useLive(),useCache(),useDLE(),fetchIfStale(), and Controller and Snapshot reads (react, react native and vue) now use them. This fixesgetResponse(),getResponseMeta()andSnapshotInterface, and deletes the duplicateResultEntryin core and rest.ControllerFetchreturns the endpoint's ownReturnType, anduseDLE()uses one to pick its return shape. ReactuseFetch()and Vue's nullableuseFetch()keep theirs because changing them would break users' annotations; those are tracked inplans/next-breaking-release.md.react/andvue/typescript-tests/endpointData.test.tsrequire each read API to return exactly the shared type. They cover endpoints with and without a schema, with value,nulland maybe-nullargs, and they check that the normalizr and endpoint copies agree. Exact equality fails on bothanyandundefined, so a copy that drifts fails the type tests.any. That is whatuseCache()always returned. The question ofanyvsunknownis in the breaking-release plan.Website changes: a new Typing endpoint data section, the
getResponsereturn types on Controller and Snapshot, and regenerated playground types.Assumptions and validation
yarn tsc --project tsconfig.test.json --noEmitpasses. The first type test fails on master with "Property 'title' does not exist on type 'never'". I checked that theexactly<>()helper rejectsany,undefinedand a too-wide union (high).SnapshotInterfacetypes it fails with the error quoted in its comment (high).yarn test --selectProjects ReactDOMon core, react, vue, endpoint, rest and normalizr: 1805 tests pass. Two suites (EntityMixin.test,resource-construction.test) fail to compile in this environment, and they fail the same way on master (high).yarn check:typeperf: every scenario stays within budget. The largest change is +2.4% (nested) and the largest drop is -1.4% (vue) (high).yarn check:doc-examples reactpasses (high).useFetch()is the one place where it would not hold, which is why it keeps its conditional (medium: verified on TS 6 and 7 locally; CI runs TS 4.0–5.3).🤖 Generated with Claude Code
https://claude.ai/code/session_01Y5C5ZB1tnwGuQL4pYksPv1
Note
Low Risk
Type-only change with no runtime behavior; risk is minor breakage where code relied on incorrect
undefinedtypings or duplicateResultEntrydefinitions.Overview
Introduces
EndpointData<E>,EndpointDataNullable<E>, and consolidatedResultEntry<E>so schema-less endpoints typedataas the fetch/resolve type instead ofundefined/never.Controller/SnapshotgetResponse()andgetResponseMeta(),SnapshotInterface,fetchIfStale(), and React/VueuseSuspense,useCache,useDLE, anduseLivenow use these aliases instead of scatteredDenormalizeNullable<E['schema']>conditionals. Types are defined in@data-client/normalizr/@data-client/endpointand re-exported from core, react, and vue.Docs add an Endpoint data typing section; changeset and compile-only tests lock read APIs to the shared types.
useFetch()(and a few Vue nullable cases) intentionally keep older conditionals, noted inplans/next-breaking-release.md.Reviewed by Cursor Bugbot for commit 7b4539a. Bugbot is set up for automated code reviews on this repo. Configure here.