Skip to content

fix: wrap useSearchParams in Suspense to fix production builds#88

Open
codexstar69 wants to merge 1 commit intogrp06:mainfrom
codexstar69:fix/wrap-usesearchparams-in-suspense
Open

fix: wrap useSearchParams in Suspense to fix production builds#88
codexstar69 wants to merge 1 commit intogrp06:mainfrom
codexstar69:fix/wrap-usesearchparams-in-suspense

Conversation

@codexstar69
Copy link

Summary

  • Wraps the root page component in <Suspense> to fix next build failure caused by useSearchParams() without a Suspense boundary
  • Two-line change: add Suspense to React import + wrap the default export

Fixes #87

Problem

next build fails with:

⨯ useSearchParams() should be wrapped in a suspense boundary at page "/"
Export encountered an error on /page: /, exiting the build.

This forces Studio to run in dev mode only, which causes:

Dev mode Production mode
RAM usage ~728 MB ~90 MB
Page serve time 1.8–2.2s per chunk (on-demand compile) ~25 ms (pre-built)
Static asset caching None (recompile every request) Hashed, long-cached
Remote access "Booting Studio..." stuck 30+ seconds Instant load

On a 2 GB VPS, dev mode OOM-kills the gateway. On a 4 GB VPS, it still causes 30+ second load times and WebSocket timeout failures ("Connecting to gateway..." hang).

Fix

- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+ import { Suspense, useCallback, useEffect, useMemo, useRef, useState } from "react";
  export default function Home() {
    return (
+     <Suspense>
        <AgentStoreProvider>
          <AgentStudioPage />
        </AgentStoreProvider>
+     </Suspense>
    );
  }

Why this works

Since Next.js 14, client components using useSearchParams() must be inside a <Suspense> boundary so Next.js can statically generate the page shell and defer the search-params-dependent subtree to the client. Without it, the static generation phase throws.

Reference: https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout

Test plan

  • npm run build completes successfully (was failing before)
  • npm run start (production mode) serves the page correctly
  • Studio connects to gateway via WebSocket in production mode
  • URL search params (e.g., ?agent=...) still work correctly
  • No visual regression — page renders identically to dev mode

🤖 Generated with Claude Code

Next.js 14+ requires client components that call useSearchParams() to be
wrapped in a <Suspense> boundary for static page generation. Without this,
`next build` fails and Studio is forced to run in dev mode — causing ~8x
higher memory usage (728MB vs 90MB), multi-second per-request compilation
latency, and WebSocket connection timeouts on remote deployments.

Fixes grp06#87

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3aa06875d0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1770 to +1774
<Suspense>
<AgentStoreProvider>
<AgentStudioPage />
</AgentStoreProvider>
</Suspense>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add an explicit fallback to the root Suspense boundary

Wrapping the entire page in <Suspense> without a fallback means the prerendered output for / can be empty (null) whenever useSearchParams() triggers the CSR bailout, so production users may see a blank screen until the client bundle hydrates (especially on slower devices/networks). This fixes the build error, but it also removes any server-rendered shell at this boundary; provide an explicit fallback (or move the boundary lower) to avoid a blank initial render.

Useful? React with 👍 / 👎.

sioakim pushed a commit to sioakim/openclaw-studio that referenced this pull request Mar 2, 2026
- Wrap root page in Suspense boundary to fix useSearchParams() build error
- Fix React hooks memoization lint blockers (destructure stable params)
- Stabilize ThemeToggle localStorage unit tests with full Storage mock

Cherry-picked from upstream PRs grp06#88, grp06#86, grp06#20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Production build fails: useSearchParams() not wrapped in Suspense boundary

1 participant