Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions .changeset/slimy-peaches-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

fix(solid-query/examples): guard the `prefetchQuery` call in the solid-start-streaming example's `/prefetch` route with `isServer || intent !== 'initial'`, so it only runs on the server and on real client-side preload/navigation, not on every client hydration, fixing the duplicate fetch reported in #8840
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