Skip to content

Suspense and Server-Side Rendering #1906

Open
@pkellner

Description

@pkellner

Bug report

Description / Observed Behavior

React 18 and SWR fails on the simplest of examples. I've created a sandbox at this URL: https://codesandbox.io/s/long-cdn-qxkc3v?file=/pages/indexSuspense.js that if your browse (to that page), you'll get the error:

error: The server could not finish this Suspense boundary, likely due to an error during server rendering. Switched to client rendering.

Expected Behavior

I expect to see a page rendered just like at the default root which is in the file /pages/index.js

Repro Steps / Code Example

Run the code sandbox, browse to http://.../indexSuspense and you will get the error I observe

Additional Context

Below is the code from code sandbox along with the associated package.json

import { Suspense } from "react";
import useSWR from "swr";

const fetcher = (url) => fetch(url).then((r) => r.json());

function Profile() {
  const { data } = useSWR("/api/cities", fetcher, {
    suspense: true
  });
  return <pre>{JSON.stringify(data, null, 2)}</pre>;
}

export default function Example() {
  return (
    <Suspense fallback={<div>Loading...</div>}>
      <Profile />
    </Suspense>
  );
}

package.json

{
  "name": "example-react-suspense",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "build": "next build",
    "dev": "next dev",
    "start": "next start"
  },
  "dependencies": {
    "next": "12.1.4",
    "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "swr": "^1.2.2"
  }
}

I've also been testing with the latest canary from next and the latest pre-release from react 18.1 and getting the same errors.

erro1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions