From 3fe2971ee17961f1d5a8419f8bd417fe37523c8c Mon Sep 17 00:00:00 2001
From: "Amir H. Hashemi" <87268103+amirhhashemi@users.noreply.github.com>
Date: Sat, 3 Jan 2026 11:49:29 +0330
Subject: [PATCH 1/3] Update `createAsync` examples
---
.../reference/data-apis/create-async.mdx | 123 ++++++++++++++----
1 file changed, 95 insertions(+), 28 deletions(-)
diff --git a/src/routes/solid-router/reference/data-apis/create-async.mdx b/src/routes/solid-router/reference/data-apis/create-async.mdx
index bfbdac5497..a46148f998 100644
--- a/src/routes/solid-router/reference/data-apis/create-async.mdx
+++ b/src/routes/solid-router/reference/data-apis/create-async.mdx
@@ -10,7 +10,7 @@ tags:
- loading
- promises
- ssr
-version: '1.0'
+version: "1.0"
description: >-
Transform promises into reactive signals with createAsync. Handle async data
with Suspense and automatic loading states.
@@ -34,21 +34,21 @@ import { createAsync } from "@solidjs/router";
```tsx
function createAsync(
- fn: (prev: T) => Promise,
- options: {
- name?: string;
- initialValue: T;
- deferStream?: boolean;
- }
+ fn: (prev: T) => Promise,
+ options: {
+ name?: string;
+ initialValue: T;
+ deferStream?: boolean;
+ }
): AccessorWithLatest;
function createAsync(
- fn: (prev: T | undefined) => Promise,
- options?: {
- name?: string;
- initialValue?: T;
- deferStream?: boolean;
- }
+ fn: (prev: T | undefined) => Promise,
+ options?: {
+ name?: string;
+ initialValue?: T;
+ deferStream?: boolean;
+ }
): AccessorWithLatest;
```
@@ -105,36 +105,103 @@ While the fetcher is executing for the first time, unless an `initialValue` is s
```tsx
import { createAsync, query } from "@solidjs/router";
-const getUserQuery = query(async (id: string) => {
- // ... Fetches the user from the server.
-}, "user");
+const getCurrentUser = query(async () => {
+ // ... Fetches the current authenticated user from the server.
+}, "currentUser");
function UserProfile() {
- const user = createAsync(() => getUserQuery());
+ const user = createAsync(() => getCurrentUser());
- return {user()?.name}
;
+ return {user()?.name}
;
}
```
-### Handling loading and errors
+### With parameter
```tsx
-import { Suspense, ErrorBoundary, For } from "solid-js";
import { createAsync, query } from "@solidjs/router";
-const getUserQuery = query(async (id: string) => {
- // ... Fetches the user from the server.
-}, "user");
+const getInvoiceQuery = query(async (invoiceId: string) => {
+ // ... Fetches the invoice details from the server.
+}, "invoice");
-function UserProfile() {
- const user = createAsync(() => getUserQuery());
+function InvoiceDetails(props: { invoiceId: string }) {
+ const invoice = createAsync(() => getInvoiceQuery(props.invoiceId));
+
+ return (
+
+
Invoice #{invoice()?.number}
+
Total: ${invoice()?.total}
+
+ );
+}
+```
+
+### With error handling and pending state
+
+```tsx
+import { createAsync, query } from "@solidjs/router";
+import { Suspense, ErrorBoundary, For } from "solid-js";
+
+const getAllRecipesQuery = query(async () => {
+ // ... Fetches the recipes from the server and throws an error if an issue occurred.
+}, "recipes");
+
+function Recipes() {
+ const recipes = createAsync(() => getAllRecipesQuery());
return (
- Could not fetch user data.
}>
- Loading user...}>
- {user()!.name}
+ Couldn't fetch any recipes!}>
+ Fetching recipes...}>
+
+ {(recipe) => (
+
+
{recipe.name}
+
Cook time: {recipe.time}
+
+ )}
+
);
}
```
+
+### With `deferStream`
+
+```tsx
+import { createAsync, query, redirect } from "@solidjs/router";
+
+const getDashboardDataQuery = query(async () => {
+ const res = await fetch("/api/dashboard");
+
+ if (res.status === 403) {
+ throw redirect("/login");
+ }
+
+ return res.json();
+}, "dashboard");
+
+function Dashboard() {
+ // Modifying response headers after streaming has started will cause an error.
+ // Since getDashboardDataQuery may trigger a redirect, which requires updating
+ // response headers, deferStream is used to ensure headers can still be modified
+ // when needed.
+ const data = createAsync(() => getDashboardDataQuery(), {
+ deferStream: true,
+ });
+
+ return (
+
+
Dashboard
+
Welcome back, {data()?.username}
+
+ );
+}
+```
+
+## Related
+
+- [query](/solid-router/reference/data-apis/query)
+- [](/reference/components/suspense)
+- [](/reference/components/error-boundary)
From 965e30a3106e7c8f8a9f727b96a1c667ddf47fbb Mon Sep 17 00:00:00 2001
From: "Amir H. Hashemi" <87268103+amirhhashemi@users.noreply.github.com>
Date: Sat, 3 Jan 2026 11:52:17 +0330
Subject: [PATCH 2/3] update
---
.../solid-router/reference/data-apis/create-async.mdx | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/routes/solid-router/reference/data-apis/create-async.mdx b/src/routes/solid-router/reference/data-apis/create-async.mdx
index a46148f998..320635a881 100644
--- a/src/routes/solid-router/reference/data-apis/create-async.mdx
+++ b/src/routes/solid-router/reference/data-apis/create-async.mdx
@@ -202,6 +202,6 @@ function Dashboard() {
## Related
-- [query](/solid-router/reference/data-apis/query)
-- [](/reference/components/suspense)
-- [](/reference/components/error-boundary)
+- [`query`](/solid-router/reference/data-apis/query)
+- [``](/reference/components/suspense)
+- [``](/reference/components/error-boundary)
From eb87b583ad36edb985c481e5212ac0cdd7bbb5e6 Mon Sep 17 00:00:00 2001
From: "Amir H. Hashemi" <87268103+amirhhashemi@users.noreply.github.com>
Date: Sun, 4 Jan 2026 09:58:12 +0330
Subject: [PATCH 3/3] remove deferStream example
---
.../reference/data-apis/create-async.mdx | 33 -------------------
1 file changed, 33 deletions(-)
diff --git a/src/routes/solid-router/reference/data-apis/create-async.mdx b/src/routes/solid-router/reference/data-apis/create-async.mdx
index 320635a881..11d1f6b809 100644
--- a/src/routes/solid-router/reference/data-apis/create-async.mdx
+++ b/src/routes/solid-router/reference/data-apis/create-async.mdx
@@ -167,39 +167,6 @@ function Recipes() {
}
```
-### With `deferStream`
-
-```tsx
-import { createAsync, query, redirect } from "@solidjs/router";
-
-const getDashboardDataQuery = query(async () => {
- const res = await fetch("/api/dashboard");
-
- if (res.status === 403) {
- throw redirect("/login");
- }
-
- return res.json();
-}, "dashboard");
-
-function Dashboard() {
- // Modifying response headers after streaming has started will cause an error.
- // Since getDashboardDataQuery may trigger a redirect, which requires updating
- // response headers, deferStream is used to ensure headers can still be modified
- // when needed.
- const data = createAsync(() => getDashboardDataQuery(), {
- deferStream: true,
- });
-
- return (
-
-
Dashboard
-
Welcome back, {data()?.username}
-
- );
-}
-```
-
## Related
- [`query`](/solid-router/reference/data-apis/query)