feat(solid-query): rewrite the adapter onto Solid 2.0's native async model #11308
solid-query-v6-pre fromrefs/pull/11308/head·merged by birkskyum(GitHub profile, opens in a new tab) View on GitHubTarget branch: solid-query-v6-pre (@tanstack/solid-query@6.x, Solid 2)
Status: ready to merge. All dependencies are published (solid-js 2.0.0-rc.4 carries the hydration fix this leans on), CI is green against the released packages, and the fullstack template has been re-validated end-to-end (build, streaming SSR, hydration, single-flight mutations in a real browser) on rc.4.
What this is#
A ground-up rewrite of the Solid Query adapter onto Solid 2.0's native
async model. The v6-pre adapter still mirrors the React adapter's
architecture — observer notifications driving a store, tracking proxies,
manually-thrown NotReadyErrors to mimic suspension — which fights the
framework: Solid 2 components don't re-render, its reactive graph already
knows how to suspend on a pending promise, hold previous values through
refetches, route rejections to error boundaries, and serialize settled
async values for streaming hydration. The rewrite hands those jobs to the
framework and keeps TanStack Query for what the framework does not do:
the cache, key identity, staleness/GC policy, retry/dedupe/cancellation,
devtools, and the ecosystem contract.
The result deletes the notification/store layer entirely:
createStore/reconcile, tracking proxies, notifyManager batching, and
observer-notification coupling are gone, replaced by
memo/projection/signal/action/optimistic primitives. QueryObserver and
MutationObserver survive only as lifecycle/policy engines (GC pinning,
mount-fetch policy, refetch intervals, focus/reconnect) with noop
listeners.
Architecture#
Reads (useBaseQuery)#
One memo is the data node: it returns either a settled value or the live
fetch promise, and the engine does the rest — first loads suspend into
<Loading>, refetches hold the previous committed value, rejections
surface to <Errored>, and on the server the settled value serializes
into the hydration payload.
A framing note: this one useQuery subsumes what React ships as three
surfaces — useQuery, the useSuspenseQuery family, and the
experimental promise field for use() interop. React's suspension is
component-scoped (the hook throws, the whole component unwinds), so its
suspense variant must forbid enabled and placeholderData and exists
as a parallel hook family. Solid's suspension is read-scoped: q.data
suspends while q.status beside it does not, so disabled queries,
placeholders, and suspense coexist in a single hook with the
useSuspenseQuery data contract (data: TData, non-optional).
- Subscription model: one version signal per hook, bumped by cache events for the query's hash (committed OR latest-computed hash — they diverge during a held transition, and settle events for a new key land before the hold commits). Every derived read pulls fresh state from the cache through it.
- Pull model: an enabled pending-idle query is fetched by the tracked
read itself (the router
query()model). This is what revives queries whose enabling flips while parked under a suspended boundary, where effects cannot run.q.fetchdedupes against policy-driven fetches; observer options are synced before pulling so the deferred options effect sees a no-op diff. - The data node IS a single auto-reconciling store projection, identical
on both sides (the Solid Router "feed
query()intocreateProjection" shape): the derive asks the cache for the answer and the engine owns everything else — the server runs it, waits, and serializes the settled value (deferStreamholds the flush); pending reads suspend into<Loading>; a hydrating client adopts the serialized value with default ('server') semantics — server truth owns the DOM for the whole hydration window, and cache writes that land mid-stream commit when the stream closes via Solid's hydration-end divergence takeover (requires solid-js >= 2.0.0-rc.4, where a latched node's mid-stream divergence is deferred rather than lost). Deep reads are fine-grained (a component readingdata[0].namere-runs only when that leaf changes), and every landing — refetch, invalidation, placeholder upgrade — reconciles into the existing proxy graph instead of replacing it, so item identity survives across fetches. The identity key is thereconcileoption (default'id', function ornullfor positional). Primitives ride a wrapper leaf. A per-hookprimedgate keeps the pull-model fetch from racing hydration: until the hook's hash-keyed registry entry has primed the cache (or was found absent), the read parks instead of fetching data the stream already carries. - Scalar metadata is a
createProjectionreconciled per-field from query state — a component reading onlyisFetchingre-runs on fetchStatus flips, not every state transition. isFetchingis the OR of two channels: committedfetchStatus(first loads, imperative reads) and the engine's pending probe (refetches inside held transitions, where committed state cannot flip mid-hold by design).- Stable promise identity across recomputes (
chainOnce), so mid-flight version bumps don't hand the engine a new pending promise per recompute. - A reactive
queryClientaccessor is honored mid-life: the version subscription and observer are re-pointed when the client changes. refetch()syncs the observer to the latest computed options at call time — under a held transition the setOptions render effect is deferred, and an imperative refetch must target what the UI is currently asking for.
SSR + streaming hydration#
Cache transfer is content-addressed — the Solid Router query() pattern,
one hydration story, no adapter-owned channel. On the server the provider
serializes every query the request touches into Solid's hydration
registry under sq:<queryHash> ({ data, t: dataUpdatedAt }, raw
pre-select data). Serialization happens at fetch-DISPATCH time, while the
request's serialization context is live, by handing seroval the fetch
promise; the payload streams whenever the fetch settles, and entries the
data nodes also serialized are emitted once (seroval cross-reference
dedupe). On the client each hook looks its own hash up in the registry,
reconstructs the cache entry through query-core hydrate() — staleness
policy intact — and only then attaches its observer. Settled entries
prime synchronously at setup; streamed entries prime as their chunk
lands, per query, so early-flushed components go live while later
boundaries still stream.
Content addressing means coverage is the cache's, not the rendered
tree's: a query prefetched in a loader and never read by any component
still transfers, and — like the router — the registry outlives the
hydration window, so a component mounted long after (lazy route,
post-hydration navigation) adopts the server's payload instead of
refetching. Entries are consumed one-shot. External hydrate() hosts
(the TanStack Start pattern) coexist: re-priming the same entry is silent
under newer-wins.
Contracts pinned by the SSR fixture tests:
- Settled-only serialization: boundaries guarantee only settled state
serializes, and every exposed field honors it. Server meta reads of an
unsettled enabled query tie themselves to the data node and suspend;
isFetching/isPendingcan never serializetrue; disabled-pending serializes as-is ('pending' IS its settled truth). - Hydration id parity: every reactive node a hook creates exists on both server and client (some inert), because hydration id assignment is positional.
- Fetch gates: no fetch is ever started inside the hydration window or while a persister is restoring; values come from adoption or node priming, and the post-attach observer issues any genuinely-needed fetch after the window closes.
- Cross-cache aggregates (
useIsFetching,useIsMutating,useMutationState): serialize their empty value (a hydrating client can only observe 0/[] at claim time) and stay latched through the hydration window, going live from the first post-hydration effect.
Mutations (useMutation)#
Rides Solid core's action primitive: one transaction across the async
gap, optimistic overlays with automatic rollback, and atomic settle.
Lifecycle callbacks are stripped from core's Mutation.execute and
re-run inside the transaction post-yield, preserving query-core's
callback-rejection semantics (success-path callback failures fail the
mutation; error-path failures report unhandled without displacing the
original error). Invalidation-triggered refetches hold the settle
transition until fresh data lands — mutation settle and cache refresh
commit together.
mutate returns the mutation promise; mutateAsync is removed (there is
no longer a fire-and-forget vs promise split to justify two entry
points).
The rest#
useQueries: N base-query layers underrepeat(positional identity), combined through a memo; the queries array is reactive in length and content.useInfiniteQuery: same read layer with_type: 'infinite'stamped so reactive key changes keepinfiniteQueryBehavior; pagers are memos over the same entry.- Counting hooks share one internal helper (
createCacheAggregate): a durable signal + optimistic override (cache events firing inside an action transaction stay observable mid-flight; out-of-transaction writes stay durable) with the hydration latch described above.
Surface changes (breaking)#
datais non-optional on query results: reads suspend (or throw to the boundary) instead of ever returningundefined. The<Show when={q.data}>loading-guard idiom is dead code now — JSX reads reach parity with plain Solid async reads.mutateAsyncremoved;mutatereturns a promise.reconcileoption re-shaped: it is now the reconciliation KEY for the data store (string | (item => any) | null, default'id') — Solid 2's projections auto-reconcile their returns, so the v5 mechanism (manualreconcile()merges into an adapter-owned store, with astructuredCloneseed hack) is core behavior now. The v5 function form(oldData, newData) => newDatais gone; corestructuralSharingstill covers cache-level referential stability underneath.suspenseoption removed: suspension is the model, and boundaries are the control point.- The
create*runtime aliases (createQuery,createMutation,createQueries,createInfiniteQuery,createIsFetching,createIsMutating,createMutationState) and theCreate*type aliases are removed, completing the deprecation from #8950 —use*is the only naming, matching the docs. isInitialLoadingremoved (deprecated alias ofisLoadingin core; its getter was byte-identical).deferStreamis now actually implemented — on the v6 line it was declared in the types but wired to nothing. It passes straight through to Solid 2's per-computationdeferStreamoption on the data node: the server holds the stream flush until the query resolves instead of letting the surrounding boundary render its fallback (engine behavior, covered by solid core's stream tests; ignored on the client).placeholderDatakeeps React semantics (client-progressive, no server fetch,isPlaceholderDataprovenance flag, masked 'success' status) and composes with SSR: the placeholder serializes, the client shows it through hydration and fetches for real after its window closes.
Intended divergences (documented in-tests)#
- A cancelled first load cannot stay idle while an enabled query is
actively read: the pull model re-demands the value (
it.skipwith rationale inuseQuery.test.tsx). Unmount, disable, or remove the query to stop it. - Mid-flight mutation state (
isPaused,failureCount) inside an action transaction holds its pre-flight face until settle — held updates commit atomically. The mutation cache remains imperatively inspectable mid-flight.
Verification#
- Full package suite green, vitest typecheck and eslint clean,
tsc --buildclean. Suites were ported test-by-test with per-file porting notes; tests asserting store/observer mechanics (render counts, notification batching) were dropped, semantics tests were kept or rewritten to DOM-level assertions. - New semantics suites for reads, mutations, queries-array, and infinite
queries; SSR fixture harness (real vite server/client builds, jsdom
hydrate()against real server HTML + streamed payload) covering string SSR, streaming with held-open boundaries, fully-buffered late hydration, prefetched-never-rendered transfer with post-hydration adoption, external-hydrate()coexistence (TanStack Start pattern), and the settled-only serialization contracts. - Template acceptance: the Solid 2.0 fullstack TanStack template (solid-js rc.0 through rc.4, production SSR server) with this adapter swapped in — suite green, hydration clean, and single-flight mutations verified end-to-end in a browser (login/rename/logout flows, mutation responses refreshing multiple queries with zero invalidation calls and zero extra fetches).
- Size: comment-stripped source is ~1,770 lines — smaller than the React adapter's core (~1,850), which additionally ships its suspense hook surface and Next.js-only streaming SSR as separate packages; this adapter's streaming hydration is included and framework-agnostic. The primitive inventory is strictly simpler.
Notes#
- Requires solid-js >= 2.0.0-rc.4 (peer dep updated) for one core piece this PR leans on: the hydration-end divergence takeover (a latched node's mid-stream cache write commits when the stream closes instead of being lost). rc.4 is published and the full suite runs green against it. The adapter performs no server reactive writes, per rc.3's deprecation.
- The devtools package is untouched; a follow-up could surface the action-transaction view.
useQueriesrows ride the same per-hook node priming automatically (each row is a full base-query layer).
- 1
View your CI Pipeline Execution ↗ for commit aef121aea50a9307907223738d89a667a4e798c9
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 6m 25s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 3s View ↗
☁️ Nx Cloud last updated this comment at
2026-08-28 22:37:43UTCReview the following changes in direct dependencies. Learn more about Socket for GitHub.
Diff Package Supply Chain
SecurityVulnerability Quality Maintenance License @solidjs/web@2.0.0-rc.3 babel-preset-solid@2.0.0-rc.2 solid-js@2.0.0-rc.3 solid-js@2.0.0-rc.4 More templates
- @tanstack/query-example-angular-auto-refetching
- @tanstack/query-example-angular-basic
- @tanstack/query-example-angular-basic-persister
- @tanstack/query-example-angular-devtools-panel
- @tanstack/query-example-angular-infinite-query-with-max-pages
- @tanstack/query-example-angular-optimistic-updates
- @tanstack/query-example-angular-pagination
- @tanstack/query-example-angular-query-options-from-a-service
- @tanstack/query-example-angular-router
- @tanstack/query-example-angular-rxjs
- @tanstack/query-example-angular-simple
- @tanstack/query-example-preact-simple
- @tanstack/query-example-lit-basic
- @tanstack/query-example-lit-pagination
- @tanstack/query-example-lit-ssr
- @tanstack/query-example-solid-astro
- @tanstack/query-example-solid-basic
- @tanstack/query-example-solid-basic-graphql-request
- @tanstack/query-example-solid-default-query-function
- @tanstack/query-example-solid-offline
- @tanstack/query-example-solid-simple
- @tanstack/query-example-solid-start-streaming
- @tanstack/query-example-vue-2.6-basic
- @tanstack/query-example-vue-2.7-basic
- @tanstack/query-example-vue-basic
- @tanstack/query-example-vue-dependent-queries
- @tanstack/query-example-vue-nuxt3
- @tanstack/query-example-vue-persister
- @tanstack/query-example-vue-simple
- @tanstack/query-example-svelte-auto-refetching
- @tanstack/query-example-svelte-basic
- @tanstack/query-example-svelte-load-more-infinite-scroll
- @tanstack/query-example-svelte-optimistic-updates
- @tanstack/query-example-svelte-playground
- @tanstack/query-example-svelte-simple
- @tanstack/query-example-svelte-ssr
- @tanstack/query-example-svelte-star-wars
- @tanstack/query-example-react-algolia
- @tanstack/query-example-react-auto-refetching
- @tanstack/query-example-react-basic
- @tanstack/query-example-react-basic-graphql-request
- @tanstack/query-example-chat
- @tanstack/query-example-react-default-query-function
- @tanstack/query-example-react-devtools-panel
- @tanstack/query-example-eslint-legacy
- @tanstack/query-example-eslint-plugin-demo
- @tanstack/query-example-react-infinite-query-with-max-pages
- @tanstack/query-example-react-load-more-infinite-scroll
- @tanstack/query-example-react-nextjs
- @tanstack/query-example-react-nextjs-app-prefetching
- @tanstack/query-example-nextjs-suspense-streaming
- @tanstack/query-example-react-offline
- @tanstack/query-example-react-optimistic-updates-cache
- @tanstack/query-example-react-optimistic-updates-ui
- @tanstack/query-example-react-pagination
- @tanstack/query-example-react-playground
- @tanstack/query-example-react-prefetching
- @tanstack/query-example-react-react-native
- @tanstack/query-example-react-router
- @tanstack/query-example-react-rick-morty
- @tanstack/query-example-react-shadow-dom
- @tanstack/query-example-react-simple
- @tanstack/query-example-react-star-wars
- @tanstack/query-example-react-suspense
@tanstack/angular-query-experimental
npm i https://pkg.pr.new/@tanstack/angular-query-experimental@11308@tanstack/eslint-plugin-query
npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@11308@tanstack/lit-query
npm i https://pkg.pr.new/@tanstack/lit-query@11308@tanstack/preact-query
npm i https://pkg.pr.new/@tanstack/preact-query@11308@tanstack/preact-query-devtools
npm i https://pkg.pr.new/@tanstack/preact-query-devtools@11308@tanstack/preact-query-persist-client
npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@11308@tanstack/query-async-storage-persister
npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@11308@tanstack/query-broadcast-client-experimental
npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@11308@tanstack/query-core
npm i https://pkg.pr.new/@tanstack/query-core@11308@tanstack/query-devtools
npm i https://pkg.pr.new/@tanstack/query-devtools@11308@tanstack/query-persist-client-core
npm i https://pkg.pr.new/@tanstack/query-persist-client-core@11308@tanstack/query-sync-storage-persister
npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@11308@tanstack/react-query
npm i https://pkg.pr.new/@tanstack/react-query@11308@tanstack/react-query-devtools
npm i https://pkg.pr.new/@tanstack/react-query-devtools@11308@tanstack/react-query-next-experimental
npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@11308@tanstack/react-query-persist-client
npm i https://pkg.pr.new/@tanstack/react-query-persist-client@11308@tanstack/solid-query
npm i https://pkg.pr.new/@tanstack/solid-query@11308@tanstack/solid-query-devtools
npm i https://pkg.pr.new/@tanstack/solid-query-devtools@11308@tanstack/solid-query-persist-client
npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@11308@tanstack/svelte-query
npm i https://pkg.pr.new/@tanstack/svelte-query@11308@tanstack/svelte-query-devtools
npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@11308@tanstack/svelte-query-persist-client
npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@11308@tanstack/vue-query
npm i https://pkg.pr.new/@tanstack/vue-query@11308@tanstack/vue-query-devtools
npm i https://pkg.pr.new/@tanstack/vue-query-devtools@11308commit:
aef121aLooks like some tests failed. The main query one passed though. Just some surrounding ones https://cloud.nx.app/runs/DjhRqLThLP?utm_source=pull-request&utm_medium=comment
I tested this in the fullstack-tanstack template and seems to function better
This is now ready to merge: solid-js 2.0.0-rc.4 shipped with the hydration-end divergence takeover this PR relies on, the peer range points at it, and CI is green against the published packages (no locally-built deps anywhere). Also re-validated the Solid 2.0 fullstack TanStack template end-to-end on rc.4 + the latest vite plugin — build, streaming SSR with the content-addressed cache payloads, clean hydration, and single-flight mutations (login/rename/logout) in a real browser.
brenelz(GitHub profile, opens in a new tab) approved these changes
Used the pkg.new link to verify Tanstack router all still passing.
birkskyum(GitHub profile, opens in a new tab) approved these changes
birkskyum(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on base/target branches other than the default branch.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID:
a36c507b-5be6-4848-825c-94a63bcea67aYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share