Skip to content

fix: One owner for endpoint data types; getResponse() types schema-less data - #4718

Merged
ntucker merged 11 commits into
masterfrom
claude/project-thread-k16mor
Nov 29, 2026
Merged

ntucker merged 11 commits into
masterfrom
claude/project-thread-k16mor

Conversation

@ntucker

@ntucker ntucker commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Requested by Nathaniel · project thread

Motivation

Bug fix.

An app reads an endpoint that has no schema with Controller.getResponse() or getResponseMeta(), or with a snapshot (including the snap an update function such as getOptimisticResponse() receives). TypeScript types data as undefined, because DenormalizeNullable<undefined> is undefined. 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 cast data to ExplorerCounts | undefined to 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

  • Types: new exported EndpointData<E>, EndpointDataNullable<E> and ResultEntry<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 fixes getResponse(), getResponseMeta() and SnapshotInterface, and deletes the duplicate ResultEntry in core and rest.
  • Kept conditionals: a few signatures keep their own conditional on purpose. ControllerFetch returns the endpoint's own ReturnType, and useDLE() uses one to pick its return shape. React useFetch() and Vue's nullable useFetch() keep theirs because changing them would break users' annotations; those are tracked in plans/next-breaking-release.md.
  • Tests: type tests in react/ and vue/typescript-tests/endpointData.test.ts require each read API to return exactly the shared type. They cover endpoints with and without a schema, with value, null and maybe-null args, and they check that the normalizr and endpoint copies agree. Exact equality fails on both any and undefined, so a copy that drifts fails the type tests.
  • Endpoint objects that aren't functions: for these, when they have no schema, data is any. That is what useCache() always returned. The question of any vs unknown is in the breaking-release plan.
// store settings are plain JSON, so this endpoint has no schema
const getSettings = new RestEndpoint({
  path: '/settings',
  process(value): { taxRate: number } {
    return value;
  },
});

const addToCart = new RestEndpoint({
  path: '/cart/items',
  method: 'POST',
  body: {} as { productId: string; price: number },
  schema: CartItem,
  getOptimisticResponse(snap, body) {
    const { data: settings } = snap.getResponse(getSettings);
    return {
      ...body,
      id: `optimistic-${snap.fetchedAt}`,
      // Before: Property 'taxRate' does not exist on type 'never'.
      tax: body.price * (settings?.taxRate ?? 0),
    };
  },
});

Website changes: a new Typing endpoint data section, the getResponse return types on Controller and Snapshot, and regenerated playground types.

Assumptions and validation

  • yarn tsc --project tsconfig.test.json --noEmit passes. The first type test fails on master with "Property 'title' does not exist on type 'never'". I checked that the exactly<>() helper rejects any, undefined and a too-wide union (high).
  • The changeset example compiles against this branch, and with the old SnapshotInterface types it fails with the error quoted in its comment (high).
  • yarn test --selectProjects ReactDOM on 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 react passes (high).
  • The aliases expand to the same conditional types as before, so user code that spells out the old return types still compiles. I checked this for the definite and nullable forms. 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).
  • It changes types only, so runtime and bundle size are unaffected (high).

🤖 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 undefined typings or duplicate ResultEntry definitions.

Overview
Introduces EndpointData<E>, EndpointDataNullable<E>, and consolidated ResultEntry<E> so schema-less endpoints type data as the fetch/resolve type instead of undefined/never.

Controller/Snapshot getResponse() and getResponseMeta(), SnapshotInterface, fetchIfStale(), and React/Vue useSuspense, useCache, useDLE, and useLive now use these aliases instead of scattered DenormalizeNullable<E['schema']> conditionals. Types are defined in @data-client/normalizr / @data-client/endpoint and 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 in plans/next-breaking-release.md.

Reviewed by Cursor Bugbot for commit 7b4539a. Bugbot is set up for automated code reviews on this repo. Configure here.

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-bot

changeset-bot Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7b4539a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
@data-client/core Patch
@data-client/endpoint Patch
@data-client/rest Patch
@data-client/graphql Patch
@data-client/normalizr Patch
@data-client/react Patch
@data-client/vue Patch
example-benchmark Patch
example-benchmark-react Patch
normalizr-github-example Patch
normalizr-redux-example Patch
normalizr-relationships Patch
test-bundlesize Patch
coinbase-lite Patch

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

@ntucker ntucker self-assigned this Nov 29, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T21:45:33.750863Z 7b4539a New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ntucker

ntucker commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

Staff Reviewer: LGTM+FOLLOW_UP ef30f69

Type-only fix that brings Controller/Snapshot getResponse()/getResponseMeta() in line with useCache()/useDLE() for schema-less endpoints. The change is right and the patch changeset fits: it widens data from undefined to ResolveType<E> | undefined, so existing casts still compile. No runtime or bundle effect. The E extends (...args) => any fallback for the Pick<EndpointInterface,…> overloads is a sensible guard.

Update for 3de41f9 (Snapshot types in endpoint and normalizr): good catch. SnapshotInterface in @data-client/endpoint and @data-client/normalizr now uses the same rule, so the snapshot that update functions like getOptimisticResponse() receive agrees with Controller.snapshot(). Still type-only and still a widening, so a patch bump across the listed packages is fine. The new test covers the endpoint interface; its snap as any cast means it checks the interface's types, not that Snapshot is assignable to it (the controller's own internal calls already check that).

FOLLOW_UP (after merge): the rule "no schema → ResolveType<E> | undefined, else DenormalizeNullable<E['schema']>" is now written out by hand in more places: three private ResponseData copies (core Controller.ts, endpoint SnapshotInterface.ts, normalizr endpoint/SnapshotInterface.ts), plus react useCache/useDLE/useSuspense/useFetch/useLive (and their .native variants) and vue useCache/useDLE/useSuspense/useLive. That repetition is how #4709 and this bug happened: one copy drifted. The endpoint/normalizr duplication is the repo's deliberate cross-package-compat pattern, so that part may stay. But core and the hooks could share one named type from normalizr/core (name chosen as public API). Keep it out of this PR, since exporting it adds public surface.

Verified by reading the diff since baae39f, the new compile-time test, and that ResolveType exists in normalizr's endpoint/utility.ts. I did not build or run tests; CI was still running when I checked.

@github-actions

Copy link
Copy Markdown
Contributor

Size Change: 0 B

Total Size: 97.5 kB

ℹ️ View Unchanged
Filename Size
examples/test-bundlesize/dist/App.js 1.27 kB
examples/test-bundlesize/dist/polyfill.js 262 B
examples/test-bundlesize/dist/rdcClient.js 9.63 kB
examples/test-bundlesize/dist/rdcEndpoint.js 7.48 kB
examples/test-bundlesize/dist/rdcNextjs.js 11.2 kB
examples/test-bundlesize/dist/rdcPipeableStream.js 8.66 kB
examples/test-bundlesize/dist/react.js 58.4 kB
examples/test-bundlesize/dist/webpack-runtime.js 593 B

compressed-size-action

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Docs preview: https://docs-site-pr-4718-data-client.vercel.app

Built from 7b4539a merged into master (this build). Locales: en (the merge queue builds every locale).

@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.64%. Comparing base (9b1a4a1) to head (7b4539a).
⚠️ Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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

@github-actions github-actions Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@ntucker

ntucker commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

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.

  • EndpointData, EndpointDataNullable and ResultEntry are now defined once in normalizr, mirrored in endpoint (the repo's usual pattern for keeping mixed package versions compatible). Core, react and vue now use them in place of about 30 hand-written E['schema'] conditionals. It also deletes the three private ResponseData copies and the duplicate ResultEntry in core and rest.
  • The ESLint rule is the part that keeps this from coming back. It turns the drift that caused fix: useDLE() types data for schema-less endpoints with nullable args #4709 and this bug into a lint error in core, react and vue. Every eslint-disable that remains has a reason, and each one is listed in plans/next-breaking-release.md with what it would break and how users migrate. That is better than a silent exception.
  • Compatibility: the aliases expand to the same conditional types as before, so code that spells out the old return types should still type-check. useFetch() is the exception, and the PR leaves it alone for that reason. The one real change is that schema-less endpoint objects that aren't functions now give any from getResponse() and Snapshot, where earlier commits in this PR gave undefined. That is wider, so nothing that compiled before breaks, and it matches what useCache() has always returned. The any → unknown question is in the breaking-release plan.
  • Public API: this adds new type exports (endpoint, core, react, vue; normalizr through its existing export *). Shipping them in a patch matches how this repo bumps 0.x releases, and the changeset and the docs (Endpoint#endpointdata, plus the Controller and Snapshot return blocks) describe them. No runtime or bundle effect, since these are types only.
  • The new type tests (react/typescript-tests/endpointData.test.ts, vue/.../endpointData.test.ts) import both the normalizr and endpoint copies, so the two mirrors can't drift apart without failing a test.

No open follow-ups from Staff. The remaining type cleanups are tracked in plans/next-breaking-release.md.

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 ResultEntry, and the changeset. I did not build or run tests. CI and Bugbot were still running when I checked.

@ntucker ntucker changed the title fix: getResponse() types data for schema-less endpoints fix: One owner for endpoint data types; getResponse() types schema-less data Nov 29, 2026
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
@ntucker
ntucker merged commit 20d93f0 into master Nov 29, 2026
43 checks passed
@ntucker
ntucker deleted the claude/project-thread-k16mor branch November 29, 2026 21:47
@github-actions github-actions Bot mentioned this pull request Nov 29, 2026
ntucker added a commit to ntucker/chess that referenced this pull request Dec 2, 2026
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>

This branch was successfully deployed

1 active deployment
docs-preview — 7b4539a8 Deployed Nov 29, 2026 by ntucker via preview / docs deploy #6368
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants