Data fetching patterns

Async reactivity loaded one product with one memo. This guide covers the other requests a real app makes: search as you type, a page that needs several things at once, pagination, data several components share, and data that stays live. These are often written with a loading flag, a request counter or an AbortController. In Solid each one is a computation that returns a promise.

Each api.* call below is any function that returns a promise: a "use server" function, a fetch wrapper, or a client SDK.


Load one thing

The baseline everything else builds on:

import { Loading, createMemo } from "solid-js";
function ProductPage(props: { id: string }) {
const product = createMemo(() => api.product(props.id));
return (
<Loading fallback={<ProductSkeleton />}>
<h1>{product().name}</h1>
<p>{product().description}</p>
</Loading>
);
}

product() is a Product. When props.id changes, the request starts again, the current product stays on screen, and the new one replaces it when it arrives. If the page should show the skeleton again for a different product, add on={props.id} to the boundary.

When the data is a list or a tree whose items need identity across updates, load it into a store instead:

const [orders] = createStore(
async () => api.orders(customerId()),
[] as Order[]
);

The response reconciles into the same proxy by id, so a row that did not change keeps its DOM. Stores covers when that matters.


Search as you type

An input writes a signal, and a memo turns the signal into results:

import { For, createMemo, createSignal, isPending, latest } from "solid-js";
function ProductSearch() {
const [query, setQuery] = createSignal("");
const results = createMemo(() => {
const text = query().trim();
if (!text) return [];
return api.search(text);
});
return (
<>
<input
type="search"
value={latest(query)}
onInput={(event) => setQuery(event.currentTarget.value)}
/>
<ul class={{ stale: isPending(results) }}>
<For each={results()}>{(product) => <li>{product.name}</li>}</For>
</ul>
</>
);
}

Type mug and three requests start, one per keystroke; the list shows the results for mug and nothing else. You do not need a request counter or an AbortController. If the response for mu arrives after the one for mug, Solid drops it. The old request still runs to completion; see Stop the work a run started if you want to cancel it.

The list does not go blank between keystrokes either. The previous results stay up, with the stale class, until the new ones arrive. An empty query never shows a spinner, because returning [] synchronously does not wait for anything.

The input binds value={latest(query)} rather than value={query()}. While results load, query() still returns the old value, and latest(query) returns what the user typed. An uncontrolled input, with no value binding, needs nothing.

Debounce at the event, not in the graph

One line in the handler keeps the graph as it is; Custom primitives packages the same idea as createDebouncedSignal:

onInput={debounce((event) => setQuery(event.currentTarget.value), 150)}

Avoid writing a debounce as an effect that copies one signal into another after a delay; Avoid unnecessary effects shows why.


Load several things for one page

A product page needs the product, its reviews, and related items. Create all three where the page is created, and they start together:

function ProductPage(props: { id: string }) {
const product = createMemo(() => api.product(props.id));
const reviews = createMemo(() => api.reviews(props.id));
const related = createMemo(() => api.related(props.id));
return (
<article>
<Loading fallback={<ProductSkeleton />}>
<ProductHeader product={product()} />
</Loading>
<Loading fallback={<ReviewsSkeleton />}>
<ReviewList reviews={reviews()} />
</Loading>
<Loading fallback={<RelatedSkeleton />}>
<RelatedGrid products={related()} />
</Loading>
</article>
);
}

Each boundary shows its content when its own data is ready, so the header can appear before the reviews. If the page should not reveal out of order, wrap the boundaries in Reveal: order="sequential" shows them top to bottom, order="together" waits for all three.

When props.id changes, all three requests start again, and the page keeps the old product until all three have loaded; then the whole page changes at once. That is usually right for a detail page, where the header and the reviews must describe the same product. If a slow section should not delay the others, give its boundary on={props.id}. The page then changes as soon as the other two have loaded, and the slow section shows its skeleton until its own data arrives. Give all three on and the page changes on the click, with each section on its skeleton until its data arrives. Async reactivity explains when the skeleton appears, and why it never appears when the same data is also read outside the boundary.


Dependent requests

A request that needs a value from another response has to wait for it:

const product = createMemo(() => api.product(props.id));
const brand = createMemo(() => api.brand(product().brandId));

brand reads product().brandId, so it cannot start until product resolves. That is correct when the data really is sequential.

The problem is a chain the data does not need. A product page that also shows the brand's other products can be written as three steps or as two independent requests:

// Avoid: each request waits for the one before it, and only the first dependency is real
const product = createMemo(() => api.product(props.id));
const brand = createMemo(() => api.brand(product().brandId));
const catalog = createMemo(() => api.brandProducts(brand().id));
// Prefer: derive from the input you already have, so the requests start together
const product = createMemo(() => api.product(props.id));
const brand = createMemo(() => api.brand(product().brandId));
const catalog = createMemo(() => api.brandProducts(product().brandId));

In the Avoid version, the catalog request does not start until the brand has arrived, although brandId was known as soon as the product was. The page waits for the sum of the three requests instead of the product request plus the longer of the other two. With attribution enabled, and the memos named through their name option, development reports a chain of three or more sequential requests:

[ASYNC_WATERFALL] 3 sequential async flights — "product" (120ms) → "brand" (80ms) → "catalog" (95ms) — 295ms serialized: each began only after the previous resolved (as far as this graph can see). If a later request doesn't need the earlier response, derive both from the same inputs so they start together; if the dependency is intrinsic, preload the dependent data or join the requests server-side.

A chain of two is recorded at info severity and does not reach the console, because two steps can be a real data dependency; three or more is a warning. Requests shorter than 50ms do not count as a step. Something updates too often explains how to enable attribution and read its reports.

When the dependency is real, remove it from the client rather than working around it:

  • Pass the input you already have. If the route knows brandId, read it from props and both requests start together.
  • Join on the server. One server function that returns the product with its brand replaces two round trips with one.

Paginate

A page number is an input like any other:

function OrderHistory() {
const [page, setPage] = createSignal(1);
const [orders] = createStore(
async () => api.orders({ page: page() }),
[] as Order[]
);
return (
<Loading fallback={<TableSkeleton />}>
<table class={{ stale: isPending(() => orders.length) }}>
<tbody>
<For each={orders}>{(order) => <OrderRow order={order} />}</For>
</tbody>
</table>
<Pager page={latest(page)} onChange={setPage} />
</Loading>
);
}

Clicking to page 2 keeps page 1 visible and dimmed until page 2 arrives, and the pager shows page 2 as selected at once because it reads latest(page). Rows that appear on both pages keep their DOM.

If the table should show a skeleton for each new page instead, move the choice to the boundary: <Loading on={page()} fallback={<TableSkeleton />}>.

Infinite scroll

Accumulate pages with the memo's previous value:

const [page, setPage] = createSignal(1);
const orders = createMemo(async (previous: Order[] = []) => {
const next = await api.orders({ page: page() });
return [...previous, ...next];
});

Each run receives the current list and returns a longer one. To reset the list when a filter changes, read the filter inside the memo and start over when it differs from the previous run's filter, or keep the accumulated list in a store keyed by filter. The simplest version is often a Show keyed on the filter around the whole list, so a filter change remounts it with page back at 1.


Share one request across components

Two components that create the same memo make two requests. Create the request once and pass the value down, or make it available through context:

function StorefrontLayout(props: ParentProps) {
const cart = createMemo(() => api.cart());
return <CartContext value={cart}>{props.children}</CartContext>;
}
function CartBadge() {
const cart = useContext(CartContext);
return <span>{cart().items.length}</span>;
}

Render CartBadge in the header and a second reader in the cart drawer, and the network tab shows one cart request. Passing an accessor through context means nothing waits for the cart until a component reads cart(), and only that component's boundary shows a fallback.

Sharing across routes

For requests shared across routes, or for deduplication and caching by argument, use query from Solid Router. It returns the same in-flight promise to every caller with the same arguments, keeps a result for a few minutes after the last reader leaves, and refetches when a mutation revalidates its key.


Keep data fresh

A memo keeps its value until an input changes. When the data on the server changes without an input changing, load it again:

import { onSettled, refresh } from "solid-js";
const stats = createMemo(() => api.dashboardStats());
onSettled(() => {
const interval = setInterval(() => refresh(stats), 30_000);
return () => clearInterval(interval);
});

Every thirty seconds the numbers update in place; nothing dims and no skeleton shows. refresh(source) re-runs the computation with the same inputs and returns a promise for the result. A plain refresh is quiet: isPending stays false, and the new value replaces the old one when it arrives. To show the reload as pending, call affects(stats) inside an action before the refresh; readers then report pending until the new value arrives.

Deep diveWhy a refresh is quiet and a changed input is not

isPending is true when an input changed and the value on screen belongs to the old input. When page goes from 1 to 2, the page 1 rows no longer match the input, so readers report pending. After a refresh, the inputs are the same and the value on screen still matches them, so nothing is pending. affects(source) marks the source as pending while the surrounding action runs, which makes a reload inside an action visible.

Polling is the fallback when the server cannot push. When it can, a live() server function returns an async iterable that a memo reads like any other async source, and each value it yields becomes the memo's new value.


Mutate, then refetch

A write goes through an action so the request and the refetch belong to one update:

const addReview = action(function* (productId: string, text: string) {
yield api.addReview(productId, text);
refresh(reviews);
});

The reviews list does not flicker: the reload runs inside the action, and the list updates once when the new data arrives. To show the new review before the server confirms it, hold the list in a createOptimisticStore and write to it before the yield; Mutations walks through that version.

With Solid Router mounted, a server function's response revalidates query reads automatically, and formAction from @solidjs/router adds form submissions on top; the Forms guide uses it.


Handle failures

A rejected promise reaches the nearest Errored boundary above the code that reads it. Place boundaries around each region that should fail on its own:

<article>
<Loading fallback={<ProductSkeleton />}>
<ProductHeader product={product()} />
</Loading>
<Errored
fallback={(error, reset) => <RetryPanel error={error()} onRetry={reset} />}
>
<Loading fallback={<ReviewsSkeleton />}>
<ReviewList reviews={reviews()} />
</Loading>
</Errored>
</article>

A failed reviews request shows the retry panel and leaves the header alone. reset retries the failed requests, and a boundary also recovers on its own when an input changes or a refresh succeeds.

Throw from the request when the response is not usable, rather than returning a { success: false } object and checking it at every read. On the server, markSafeError marks a message that is intended for the client; unmarked errors are replaced with a generic message in production.


Common problems

The search box lags behind what I typed

The input is bound with value={query()}, and query() keeps its old value while the results load, so the input shows the previous text until the request finishes. Bind value={latest(query)}, or leave the input uncontrolled.

Opening another product keeps showing the old one

That is the default after the first load: the current product stays on screen while the new one loads. Add on={props.id} to the Loading boundary when a changed subject should show the skeleton again, and pass the value rather than the accessor.

Two components make the same request

Each component created its own memo, and each memo is its own request. Create the memo once in a common ancestor and pass the accessor down or through context, or use Solid Router's query when the callers are on different routes.

refresh runs but nothing shows as loading

A plain refresh keeps the same inputs, so isPending stays false and the new value replaces the old one quietly. Call affects(source) inside an action before the refresh when the reload should show as pending.

One request waits for another that it does not need

A memo reads a value from another memo's response when the same value was available from props or the route. Read the input directly so both requests start together; with attribution enabled, a chain of three or more is reported as [ASYNC_WATERFALL].


Recap

  • Make each request a memo or a store created where the data is needed, or higher when it should start earlier.
  • Create requests that do not depend on each other in the same scope so they run in parallel; derive from inputs you already have rather than from another response.
  • Wrap the smallest region each Loading fallback should replace, and set on where a changed subject should show the fallback again.
  • Read latest in controls whose writes feed a request, and mark waiting content with isPending.
  • Leave stale responses and loading flags to Solid; returning a synchronous value never shows a fallback.
  • Reload with refresh, and add affects inside an action when the reload should show as pending.
  • Throw from a request that fails and cover each region that should fail on its own with Errored.

Next steps

Last updated: 11/17/26, 5:53 PMEdit this pageReport an issue with this page