#Queries not getting refetched.

2 messages · Page 1 of 1 (latest)

limber abyss
#

I'm using tanstack start, and this is my code at __root.tsx:

  loader: async ({ context }) => {
    const userId = context.session?.data?.user.id
    if (userId) {
      const config = await context.queryClient.ensureQueryData({
        queryKey: CONFIG_QUERY_KEY,
        queryFn: async () => {
          return await getSettingIsoFn({
            userId,
          })
        },
        staleTime: 0,
      })
      console.log(config)
      return { config }
    }
  },

I'm confused why it doesnt get refetched. while the console.log() inside the code got logged everytime i change page.

  • I try using fetchQuery and it works. but for the purpose of learning, why the staleTime doesnt work in ensureQueryData?

thanks

astral umbra