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

Suspense components streamed with renderToReadableStream and Bun.serve() cause render to be aborted #16721

Open
jmuzina opened this issue Jan 24, 2025 · 1 comment
Labels
bug Something isn't working needs triage

Comments

@jmuzina
Copy link

jmuzina commented Jan 24, 2025

What version of Bun is running?

1.1.43

What platform is your computer?

Darwin 24.0.0 arm64 arm

What steps can reproduce the bug?

An error is thrown by react-dom/server when serving a request for a serverside-rendered (using renderToReadableSteam) React app that includes a React.Suspense component.

Reproduction steps:

  1. Clone my reproduction repo
  2. Install dependencies with Bun: bun install
  3. Run React server with Node: bun run ssr:node. Open the app and see that the suspended Button component resolves after 2 seconds and no errors are thrown in the serverside or clientside consoles.
  4. Run React server with Bun; bun run ssr:bun. Open the app and see that the Button component remains suspended after 2 seconds, is resolved in the serverside console but not the clientside console, and the following error is thrown in the server console:
8169 |   try {
8170 |     var abortableTasks = request.abortableTasks;
8171 |     if (0 < abortableTasks.size) {
8172 |       var error =
8173 |         void 0 === reason
8174 |           ? Error("The render was aborted by the server without a reason.")
                   ^
error: The render was aborted by the server without a reason.
      at abort (/home/jmuzina/software/work/canonical/repos/react-repro/node_modules/react-dom/cjs/react-dom-server.bun.development.js:8174:13)
      at cancel (/home/jmuzina/software/work/canonical/repos/react-repro/node_modules/react-dom/cjs/react-dom-server.bun.development.js:8262:17)
      at close (3:17)

What is the expected behavior?

Bun can serve serverside-rendered React applications that include Suspense components, and the Suspense components behave as they do in Node (suspending and displaying fallback content until the component's promises are resolved).

What do you see instead?

Error thrown in server console:

8169 |   try {
8170 |     var abortableTasks = request.abortableTasks;
8171 |     if (0 < abortableTasks.size) {
8172 |       var error =
8173 |         void 0 === reason
8174 |           ? Error("The render was aborted by the server without a reason.")
                   ^
error: The render was aborted by the server without a reason.
      at abort (/home/jmuzina/software/work/canonical/repos/react-repro/node_modules/react-dom/cjs/react-dom-server.bun.development.js:8174:13)
      at cancel (/home/jmuzina/software/work/canonical/repos/react-repro/node_modules/react-dom/cjs/react-dom-server.bun.development.js:8262:17)
      at close (3:17)

Suspense components are not un-suspended until a rerender occurs on the clientside. The page does not fully load unless the user or some code causes a re-rerender.

Additional information

I have also filed a bug with React as I can't tell if this is a bug with react-dom or Bun itself.
facebook/react#32159

@jmuzina jmuzina added bug Something isn't working needs triage labels Jan 24, 2025
@jmuzina
Copy link
Author

jmuzina commented Jan 30, 2025

Per the React WG, Suspense is intended for use with PipeableStream, not ReadableStream. As far as I can tell, react-dom's Bun renderer does not implement renderToPipeableStream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant