Skip to content

encounter "Fallback data is required when using Suspense in SSR." in suspense mode with 2.3.5 #4155

@arvinxx

Description

@arvinxx

Bug report

sw 2.3.5 cause LobeChat build failed while 2.3.4 not.

 ⚠ Using edge runtime on a page currently disables static generation for that page
   Generating static pages (0/377) ...
   Generating static pages (94/377) 
   Generating static pages (188/377) 
   Generating static pages (282/377) 
Error occurred prerendering page "/en-US__0__dark/chat". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Fallback data is required when using Suspense in SSR.
    at useSWRHandler (/vercel/path0/.next/server/chunks/30323.js:209816:19)
    at /vercel/path0/.next/server/chunks/30323.js:281382:16
    at useSWRArgs (/vercel/path0/.next/server/chunks/30323.js:281404:16)
    at useFetchPluginStore (/vercel/path0/.next/server/chunks/24346.js:59621:92)
    at useControls (/vercel/path0/.next/server/app/[variants]/(main)/chat/(workspace)/page.js:13895:5)
    at /vercel/path0/.next/server/app/[variants]/(main)/chat/(workspace)/page.js:42509:85
    at nF (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:76:46843)
    at nH (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:76:48618)
    at nH (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:76:64107)
    at nW (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:76:67762)
Export encountered an error on /[variants]/(main)/chat/(workspace)/page: /en-US__0__dark/chat, exiting the build.
 ⨯ Next.js build worker exited with code: 1 and signal: null
error: script "build" exited with code 1
Error: Command "bun run build" exited with 1

Description / Observed Behavior

we use swr with some code like this:

useFetchTopics: (enable, sessionId) =>
    useClientDataSWR<ChatTopic[]>(
      enable ? [SWR_USE_FETCH_TOPIC, sessionId] : null,
      async ([, sessionId]: [string, string]) => topicService.getTopics({ sessionId }),
      {
        suspense: true,
        fallbackData: [],
        onSuccess: (topics) => {
          const nextMap = { ...get().topicMaps, [sessionId]: topics };

          // no need to update map if the topics have been init and the map is the same
          if (get().topicsInit && isEqual(nextMap, get().topicMaps)) return;

          set(
            { topicMaps: nextMap, topicsInit: true },
            false,
            n('useFetchTopics(success)', { sessionId }),
          );
        },
      },
    ),

and it works fine with 2.3.4 but failed in next build with Prerender in 2.3.5.

here is the failing test action: https://github.com/lobehub/lobe-chat/actions/runs/16848284108/job/47731232183

Expected Behavior

build success with next like 2.3.4

Repro Steps / Code Example

  1. git clone https://github.com/lobehub/lobe-chat

  2. git checkout reproduction/swr-2.3.5

  3. npm run build

it only failed with swr@2.3.5

Additional Context

I have pin swr to 2.3.4 to fix the build temporarily lobehub/lobehub#8746

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions