Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions examples/solid/solid-start-streaming/src/routes/prefetch.tsx
Original file line number Diff line number Diff line change
@@ -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 }),
)
}
},
}

Expand Down