Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudflare Suspense streaming doesn't work with React 19 #39

Open
gavriguy opened this issue Dec 14, 2024 · 0 comments
Open

Cloudflare Suspense streaming doesn't work with React 19 #39

gavriguy opened this issue Dec 14, 2024 · 0 comments

Comments

@gavriguy
Copy link

gavriguy commented Dec 14, 2024

Hi,
It seams that trying to use Suspense as mentioned in the docs - https://reactrouter.com/how-to/suspense#with-react-19
doesn't work with Cloudfalre. The response waits to the NonCriticalUI to resolve on the server before rendering the full page.

import * as React from "react";
import { Await } from "react-router";
import type { Route } from "./+types/my-route";

export async function loader({}: Route.LoaderArgs) {
  // note this is NOT awaited
  let nonCriticalData = new Promise((res) =>
    setTimeout(() => res("non-critical"), 5000)
  );

  let criticalData = await new Promise((res) =>
    setTimeout(() => res("critical"), 300)
  );

  return { nonCriticalData, criticalData };
}

export default function MyComponent({
  loaderData,
}: Route.ComponentProps) {
  let { criticalData, nonCriticalData } = loaderData;

  return (
    <div>
      <h1>Streaming example</h1>
      <h2>Critical data value: {criticalData}</h2>

      <React.Suspense fallback={<div>Loading...</div>}>
        <NonCriticalUI p={nonCriticalData} />
      </React.Suspense>
    </div>
  );
}

function NonCriticalUI({ p }: { p: Promise<string> }) {
  let value = React.use(p);
  return <h3>Non critical value {value}</h3>;
}
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

No branches or pull requests

1 participant