Skip to content

Run loader on client and server #4342

@ilarramendi

Description

@ilarramendi

Which project does this relate to?

Start

Describe the bug

I'm using TanStack Start with TanStack Query and noticing that preloaded query data can become stale when served from SSR.

I’m using defaultPreloadStaleTime: 0, which I’d expect to cause the loader to run on both the server and the client, ensuring fresh data even after SSR and hydrating the queries in the client. But currently, the loader only runs on the server during the initial page render.

If that server-rendered response is cached (e.g. by a CDN or browser), the client doesn't re-run the loader, so the data can remain stale untill its used by a component, when it should be refreshed by the loader.

Your Example Website or App

https://stackblitz.com/github/tanstack/router/tree/main/examples/react/start-basic-react-query

Steps to Reproduce the Bug or Issue

I think this is an expected behavior but this can be tested just adding a log to any loader using start

Expected behavior

defaultPreloadStaleTime being taken into consideration and run the loader in the client side too if it makes sense based on the configure time

Screenshots or Videos

No response

Platform

  • OS: any
  • Browser: any
  • Version: latest/alpha

Additional context

No response

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