Skip to content

getHeaders() not returning proper headers when called inside server function via SSR #3233

Description

@MarcMogdanz

Which project does this relate to?

Start

Describe the bug

I have a beforeLoad which checks if the user is authenticated on all protected pages. In there I call a server function which does the auth check based on a token which is in a cookie. If I client side navigate I can see that the server function works properly and has access to the cookie since the request is being made directly from client to the server function. But on the first render if a user visits the page the server will internally call the server function but not pass down the correct headers so the server function will redirect to the login page in my case.

Your Example Website or App

https://codesandbox.io/p/devbox/tanstack-router-3054-forked-l323n3

Steps to Reproduce the Bug or Issue

  1. Start server using bun dev
  2. Go to /
  3. Logs show the output of getHeaders() inside the beforeLoad and loader (working) and a server function called via them (not working)

Expected behavior

I'd expect that a getHeaders() call inside a server function which was triggered through the server doing SSR would share the same headers as the client request that triggered it or as if the client made the call directly to the server function.

So in case of my SSR only example, I'd expect the getHeaders() calls inside the server function to return the same headers as for loader and beforeLoad.

Screenshots or Videos

No response

Platform

OS: MacOS 14.2
Browser: Chromium
Version: 131.0.6778.108

Additional context

It seemed to work around version 1.92.1, but can't confirm 100%, but it confirmed does not work on 1.97.19.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions