Skip to content

Commit 782a9e6

Browse files
devallibusclaude
andcommitted
fix(playground): use useServerFn+onMount pattern for session loading
Replace createResource with the useServerFn+onMount+createSignal pattern used by all other routes (shaders.index, shaders.$name, etc.). The createResource approach doesn't integrate with TanStack Router's SSR streaming — it silently renders nothing during server-side rendering, causing the blank page. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7bb8e07 commit 782a9e6

1 file changed

Lines changed: 23 additions & 27 deletions

File tree

apps/web/src/routes/playground.tsx

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createFileRoute, useNavigate, useSearch } from '@tanstack/solid-router'
22
import { createServerFn } from '@tanstack/solid-start'
3-
import { createEffect, createResource, on, Show, Suspense } from 'solid-js'
4-
import { isServer } from 'solid-js/web'
3+
import { useServerFn } from '@tanstack/solid-start'
4+
import { createSignal, onMount, Show } from 'solid-js'
55
import PlaygroundLayout from '../components/playground/PlaygroundLayout'
66
import type { PlaygroundSession } from '../lib/playground-types'
77

@@ -30,40 +30,36 @@ export const Route = createFileRoute('/playground')({
3030
function PlaygroundPage() {
3131
const search = useSearch({ from: '/playground' })
3232
const navigate = useNavigate()
33+
const fetchSession = useServerFn(getOrCreateSession)
34+
const [session, setSession] = createSignal<PlaygroundSession | null>(null)
35+
const [loading, setLoading] = createSignal(true)
3336

34-
const [session] = createResource(
35-
() => search.session,
36-
async (sessionId) => {
37-
const result = await getOrCreateSession({ data: { sessionId } })
38-
return result as PlaygroundSession
39-
},
40-
)
37+
onMount(async () => {
38+
try {
39+
const result = await fetchSession({ data: { sessionId: search.session } })
40+
const s = result as PlaygroundSession
41+
setSession(s)
4142

42-
// Update URL with session ID after hydration (client-only)
43-
createEffect(
44-
on(
45-
() => session(),
46-
(s) => {
47-
if (isServer || !s) return
48-
if (search.session !== s.id) {
49-
navigate({ search: { session: s.id }, replace: true })
50-
}
51-
},
52-
{ defer: true },
53-
),
54-
)
43+
// Update URL with session ID if it changed or was missing
44+
if (search.session !== s.id) {
45+
navigate({ search: { session: s.id }, replace: true })
46+
}
47+
} finally {
48+
setLoading(false)
49+
}
50+
})
5551

5652
return (
57-
<Suspense
53+
<Show
54+
when={session()}
55+
keyed
5856
fallback={
5957
<div class="flex h-[calc(100vh-56px)] items-center justify-center">
6058
<div class="h-6 w-6 animate-spin rounded-full border-2 border-accent border-t-transparent" />
6159
</div>
6260
}
6361
>
64-
<Show when={session()} keyed>
65-
{(s) => <PlaygroundLayout session={s} />}
66-
</Show>
67-
</Suspense>
62+
{(s) => <PlaygroundLayout session={s} />}
63+
</Show>
6864
)
6965
}

0 commit comments

Comments
 (0)