diff --git a/src/routes/solid-start/building-your-application/data-fetching.mdx b/src/routes/solid-start/building-your-application/data-fetching.mdx index 497499b781..17e5fdb082 100644 --- a/src/routes/solid-start/building-your-application/data-fetching.mdx +++ b/src/routes/solid-start/building-your-application/data-fetching.mdx @@ -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 }); +``` + +:::