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
14 changes: 14 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,17 @@ 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 streaming begins, response headers (including status and cookies) are sent and cannot be changed.
Any header-modifying logic within a server function, such as redirects or APIs like `useSession` that set cookies, must run before streaming starts, or this error will occur:

**"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 });
```

Comment on lines +48 to +56
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**"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 });
```
To avoid this, disable streaming for queries that may modify headers by enabling the [`deferStream`](/solid-router/reference/data-apis/create-async#deferstream):
```tsx
const user = createAsync(() => getCurrentUserQuery(), { deferStream: true });

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep the error message. It's a common and vague message, and people might try to search it in the docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case, we should leave it inline.

:::