diff --git a/examples/solid/solid-start-streaming/src/routes/prefetch.tsx b/examples/solid/solid-start-streaming/src/routes/prefetch.tsx index 73623302ebb..1463969cf81 100644 --- a/examples/solid/solid-start-streaming/src/routes/prefetch.tsx +++ b/examples/solid/solid-start-streaming/src/routes/prefetch.tsx @@ -1,13 +1,24 @@ import { useQueryClient } from '@tanstack/solid-query' import { isServer } from 'solid-js/web' import { Title } from '@solidjs/meta' +import type { RoutePreloadFuncArgs } from '@solidjs/router' import { UserInfo, userInfoQueryOpts } from '~/components/user-info' export const route = { - load: () => { - const queryClient = useQueryClient() - // Prefetching the user info and caching it for 15 seconds. - queryClient.prefetchQuery(userInfoQueryOpts({ sleep: 500, gcTime: 15000 })) + load: ({ intent }: RoutePreloadFuncArgs) => { + // The router re-runs `load` on the client during hydration, with the + // same `intent: "initial"` the server call gets. UserInfo's useQuery + // already hydrates that data on the client through its own resource, + // so prefetching again here just duplicates the fetch. Hover preload + // (`intent: "preload"`) and real navigation (`intent: "navigate"`) + // still need to run, since neither has server-rendered data to use. + if (isServer || intent !== 'initial') { + const queryClient = useQueryClient() + // Prefetching the user info and caching it for 15 seconds. + queryClient.prefetchQuery( + userInfoQueryOpts({ sleep: 500, gcTime: 15000 }), + ) + } }, }