Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/routes/solid-start/building-your-application/data-fetching.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,19 @@ const getCurrentUserQuery = query(async (id: string) => {
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.
Otherwise, it redirects the user to the login page.
All of these operations are performed completely on the server regardless of how the query is called.

:::caution[Modifying headers after streaming]
Once a response starts streaming, its headers (including the status code and cookies) are immediately sent to the client and **cannot be modified**.

Any server-side operation that changes headers, such as performing a redirect (`3xx` status) or using APIs like `useSession` that modify cookies, must happen **before** streaming begins.
Otherwise, you'll encounter errors like:

**"Cannot set headers after they are sent to the client."**

To avoid this, disable streaming for queries that may modify headers by enabling the [`deferStream`](/solid-router/reference/data-apis/create-async#deferstream) option.

```tsx
const user = createAsync(() => getCurrentUserQuery(), { deferStream: true });
```

:::