Skip to content

Commit 76a601a

Browse files
committed
fix max readers during SSR
1 parent edbcf86 commit 76a601a

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { BuilderLayout } from './BuilderLayout'
2+
import { BuilderProvider } from './BuilderProvider'
3+
4+
export function BuilderPage() {
5+
return (
6+
<BuilderProvider>
7+
<BuilderLayout />
8+
</BuilderProvider>
9+
)
10+
}

src/components/builder/ExplorerPanel.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
* Includes "Addons" tab for viewing per-feature file artifacts.
77
*/
88

9+
import * as React from 'react'
910
import { useState, useMemo, useEffect, useCallback } from 'react'
10-
import { useNavigate, useSearch } from '@tanstack/react-router'
11+
import { ClientOnly, useNavigate, useSearch } from '@tanstack/react-router'
1112
import { twMerge } from 'tailwind-merge'
1213
import { createHighlighter, type HighlighterGeneric } from 'shiki'
1314
import { Code, Play } from 'lucide-react'
@@ -19,9 +20,14 @@ import {
1920
useBuilderStore,
2021
} from './store'
2122
import { partners } from '~/utils/partners'
22-
import { PreviewPanel } from './webcontainer'
2323
import type { FeatureId, AttributedCompileOutput } from '~/builder/api'
2424

25+
const LazyPreviewPanel = React.lazy(() =>
26+
import('~/components/builder/webcontainer/PreviewPanel').then((m) => ({
27+
default: m.PreviewPanel,
28+
})),
29+
)
30+
2531
// Lazy highlighter singleton for syntax highlighting
2632
let highlighterPromise: Promise<HighlighterGeneric<any, any>> | null = null
2733

@@ -827,7 +833,11 @@ export function ExplorerPanel() {
827833
{viewMode === 'preview' ? (
828834
/* Full-width preview */
829835
<div className="flex-1 min-w-0 h-full">
830-
<PreviewPanel files={compiledOutput?.files || null} />
836+
<ClientOnly>
837+
<React.Suspense fallback={null}>
838+
<LazyPreviewPanel files={compiledOutput?.files || null} />
839+
</React.Suspense>
840+
</ClientOnly>
831841
</div>
832842
) : (
833843
<>
Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,2 @@
11
export { PreviewPanel } from './PreviewPanel'
22
export { PreviewLoading } from './PreviewLoading'
3-
export {
4-
useWebContainerStore,
5-
useSetupStep,
6-
usePreviewUrl,
7-
useWebContainerError,
8-
useTerminalOutput,
9-
useIsUpdating,
10-
type SetupStep,
11-
SETUP_STEP_LABELS,
12-
} from './useWebContainerStore'

src/routes/builder.index.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
import { createFileRoute, Link } from '@tanstack/react-router'
1+
import * as React from 'react'
2+
import { ClientOnly, createFileRoute, Link } from '@tanstack/react-router'
23
import { z } from 'zod'
34
import { seo } from '~/utils/seo'
4-
import { BuilderProvider, BuilderLayout } from '~/components/builder'
5+
6+
const LazyBuilderPage = React.lazy(() =>
7+
import('~/components/builder/BuilderPage.client').then((m) => ({
8+
default: m.BuilderPage,
9+
})),
10+
)
511

612
// Search params schema for shareable URLs
713
const builderSearchSchema = z
@@ -44,9 +50,11 @@ export const Route = createFileRoute('/builder/')({
4450
function RouteComponent() {
4551
return (
4652
<div className="h-[calc(100dvh-var(--navbar-height))] w-full overflow-hidden">
47-
<BuilderProvider>
48-
<BuilderLayout />
49-
</BuilderProvider>
53+
<ClientOnly>
54+
<React.Suspense fallback={null}>
55+
<LazyBuilderPage />
56+
</React.Suspense>
57+
</ClientOnly>
5058
</div>
5159
)
5260
}

vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default defineConfig({
3939
'file-selector',
4040
'normalize-wheel',
4141
'@tanstack/react-hotkeys',
42+
'@webcontainer/api',
4243
],
4344
},
4445
optimizeDeps: {

0 commit comments

Comments
 (0)