Skip to content

Commit 25cf373

Browse files
Merge branch 'main' into feat/migrating-to-v2-guide
2 parents 3c5ed9e + e4ebfae commit 25cf373

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/routes/solid-start/building-your-application/data-fetching.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,17 @@ const getCurrentUserQuery = query(async (id: string) => {
4141
In this example, the `getCurrentUserQuery` retrieves the session data, and if an authenticated user exists, it gets their information from the database and returns it.
4242
Otherwise, it redirects the user to the login page.
4343
All of these operations are performed completely on the server regardless of how the query is called.
44+
45+
:::caution[Modifying headers after streaming]
46+
Once streaming begins, response headers (including status and cookies) are sent and cannot be changed.
47+
Any header-modifying logic within a server function, such as redirects or APIs like `useSession` that set cookies, must run before streaming starts;
48+
otherwise, this error will occur:
49+
`Cannot set headers after they are sent to the client.`
50+
51+
To avoid this, disable streaming for queries that may modify headers by enabling the [`deferStream`](/solid-router/reference/data-apis/create-async#deferstream) option.
52+
53+
```tsx
54+
const user = createAsync(() => getCurrentUserQuery(), { deferStream: true });
55+
```
56+
57+
:::

0 commit comments

Comments
 (0)