TanStackT
TanStackโ€ข8mo agoโ€ข
3 replies
then-purple

Invalidate context

Hey guys ! ๐Ÿ‘‹

I think i'm missing something on how to properly invalidate the root context.

I created a router with a context like this :
const router = createRouter({
  routeTree,
  context: {
    session: async () => {
      const session = await authClient.getSession();
      return session;
    },
    queryClient,
    establishmentId: document.cookie
      .split("; ")
      .find((row) => row.startsWith("establishment_id="))
        ?.split("=")[1] ?? null
  },
  defaultPreload: "intent",
  scrollRestoration: true,
  defaultStructuralSharing: true,
  defaultPreloadStaleTime: 0,
});

So every time i use useRouter().invalidate() i'm expecting the value of establishmentId to be recomputed ?
It doesn't seem to be the case because even if i update the cookie, the value does not change.
I tried to log the value of establishmentId by using a self called function and it seems to be only called once

Am i missing something about context (or maybe it's the cookie usage)
Was this page helpful?