Repository: facebook/react
File: packages/react-dom/src/server/react-dom-server.bun.js (JavaScript)

Code before:
/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

export * from './ReactDOMFizzServerBun.js';
export {
  renderToPipeableStream,
  resumeToPipeableStream,
  // $FlowFixMe[cannot-resolve-module]
} from './ReactDOMFizzServerNode.js';
export {
  prerenderToNodeStream,
  prerender,
  resumeAndPrerenderToNodeStream,
  resumeAndPrerender,
  // $FlowFixMe[cannot-resolve-module]
} from './ReactDOMFizzStaticNode.js';


Review comment (bug):
I did try to add it to `inlinedHostConfigs.js`, but then I got weird errors that didn't make too much sense to me. If it worked in normal node and the built one included the exports (that are usable correctly), then I can't understand how bun fails when exporting it.

<details>
<summary>An error</summary>

```ts
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ packages/react-dom/src/server/ReactDOMFizzServerNode.js:50:38

Cannot call startFlowing with destination bound to destination because: [incompatible-call]
 • Either stream$Writable [1] is incompatible with ReadableStreamController [2].
 • Or MightBeFlushable [3] is incompatible with ReadableStreamController [2].

        packages/react-dom/src/server/ReactDOMFizzServerNode.js
        47│ ensureCorrectIsomorphicReactVersion();
        48│
        49│ function createDrainHandler(destination: Destination, request: Request) {
        50│   return () => startFlowing(request, destination);
        51│ }
        52│
        53│ function createCancelHandler(request: Request, reason: string) {

        packages/react-server/src/ReactServerStreamConfigBun.js
    [2] 12│ type BunReadableStreamController = ReadableStreamController & {

        packages/react-server/src/ReactServerStreamConfigNode.js
 [1][3] 19│ export type Destination = Writable & MightBeFlushable;


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ packages/react-dom/src/server/ReactDOMFizzServerNode.js:50:38

Cannot call startFlowing with destination bound to destination because: [incompatible-call]
 • Either inexact stream$Writable [1] is incompatible with exact object type [2].
 • Or inexact MightBeFlushable [3] is incompatible with exact object type [2].

        packages/react-dom/src/server/ReactDOMFizzServerNode.js
        47│ ensureCorrectIsomorphicReactVersion();
        48│
        49│ function createDrainHandler(destination: Destination, request: Request) {
        50│   return () => startFlowing(request, destination);
        51│ }
        52│
        53│ function createCancelHandler(request: Request, reason: string) {

        packages/react-server/src/ReactServerStreamConfigBun.js
    [2] 12│ type BunReadableStreamController = ReadableStreamController & {
        13│   end(): mixed,
        14│   write(data: Chunk | BinaryChunk): void,
        15│   error(error: Error): void,
        16│   flush?: () => void,
        17│ };

        packages/react-server/src/ReactServerStreamConfigNode.js
 [1][3] 19│ export type Destination = Writable & MightBeFlushable;


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ packages/react-dom/src/server/ReactDOMFizzServerNode.js:151:29

Cannot call startFlowing with destination bound to destination because stream$Writable [1] is incompatible with
ReadableStreamController [2]. [incompatible-call]

     packages/react-dom/src/server/ReactDOMFizzServerNode.js
 [1] 143│     pipe<T: Writable>(destination: T): T {
        :
     148│       }
     149│       hasStartedFlowing = true;
     150│       prepareForStartFlowingIfBeforeAllReady(request);
     151│       startFlowing(request, destination);
     152│       destination.on('drain', createDrainHandler(destination, request));
     153│       destination.on(
     154│         'error',

     packages/react-server/src/ReactServerStreamConfigBun.js
 [2]  12│ type BunReadableStreamController = ReadableStreamController & {


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ packages/react-dom/src/server/ReactDOMFizzServerNode.js:151:29

Cannot call startFlowing with destination bound to destination because inexact stream$Writable [1] is incompatible with
exact object type [2]. [incompatible-exact]

     packages/react-dom/src/server/ReactDOMFizzServerNode.js
 [1] 143│     pipe<T: Writable>(destination: T): T {
        :
     148│       }
     149│       hasStartedFlowing = true;
     150│       prepareForStartFlowingIfBeforeAllReady(request);
     151│       startFlowing(request, destination);
     152│       destination.on('drain', createDrainHandler(destination, request));
     153│       destination.on(
     154│         'error',

     packages/react-server/src/ReactServerStreamConfigBun.js
 [2]  12│ type BunReadableStreamController = ReadableStreamController & {
      13│   end(): mixed,
      14│   write(data: Chunk | BinaryChunk): void,
      15│   error(error: Error): void,
      16│   flush?: () => void,
      17│ };


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ packages/react-dom/src/server/ReactDOMFizzServerNode.js:233:35

Cannot call startFlowing with writable bound to destination because stream$Writable [1] is incompatible with
ReadableStreamController [2]. [incompatible-call]

     packages/react-dom/src/server/ReactDOMFizzServerNode.js
 [1] 224│       let writable: Writable;
        :
     230│               createFakeWritableFromReadableStreamController(controller);
     231│           },
     232│           pull: (controller): ?Promise<void> => {
     233│             startFlowing(request, writable);
     234│           },
     235│           cancel: (reason): ?Promise<void> => {
     236│             stopFlowing(request);

     packages/react-server/src/ReactServerStreamConfigBun.js
 [2]  12│ type BunReadableStreamController = ReadableStreamController & {


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ packages/react-dom/src/server/ReactDOMFizzServerNode.js:233:35

Cannot call startFlowing with writable bound to destination because inexact stream$Writable [1] is incompatible with
exact object type [2]. [incompatible-exact]

     packages/react-dom/src/server/ReactDOMFizzServerNode.js
 [1] 224│       let writable: Writable;
        :
     230│               createFakeWritableFromReadableStreamController(controller);
     231│           },
     232│           pull: (controller): ?Promise<void> => {
     233│             startFlowing(request, writable);
     234│           },
     235│           cancel: (reason): ?Promise<void> => {
     236│             stopFlowing(request);

     packages/react-server/src/ReactServerStreamConfigBun.js
 [2]  12│ type BunReadableStreamController = ReadableStreamController & {
      13│   end(): mixed,
      14│   write(data: Chunk | BinaryChunk): void,
      15│   error(error: Error): void,
      16│   flush?: () => void,
      17│ };


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ packages/react-dom/src/server/ReactDOMFizzServerNode.js:344:29

Cannot call startFlowing with destination bound to destination because stream$Writable [1] is incompatible with
ReadableStreamController [2]. [incompatible-call]

     packages/react-dom/src/server/ReactDOMFizzServerNode.js
 [1] 337│     pipe<T: Writable>(destination: T): T {
     338│       if (hasStartedFlowing) {
     339│         throw new Error(
     340│           'React currently only supports piping to one writable stream.',
     341│         );
     342│       }
     343│       hasStartedFlowing = true;
     344│       startFlowing(request, destination);
     345│       destination.on('drain', createDrainHandler(destination, request));
     346│       destination.on(
     347│         'error',

     packages/react-server/src/ReactServerStreamConfigBun.js
 [2]  12│ type BunReadableStreamController = ReadableStreamController & {


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ packages/react-dom/src/server/ReactDOMFizzServerNode.js:344:29

Cannot call startFlowing with destination bound to destination because inexact stream$Writable [1] is incompatible with
exact object type [2]. [incompatible-exact]

     packages/react-dom/src/server/ReactDOMFizzServerNode.js
 [1] 337│     pipe<T: Writable>(destination: T): T {
     338│       if (hasStartedFlowing) {
     339│         throw new Error(
     340│           'React currently only supports piping to one writable stream.',
     341│         );
     342│       }
     343│       hasStartedFlowing = true;
     344│       startFlowing(request, destination);
     345│       destination.on('drain', createDrainHandler(destination, request));
     346│       destination.on(
     347│         'error',

     packages/react-server/src/ReactServerStreamConfigBun.js
 [2]  12│ type BunReadableStreamController = ReadableStreamController & {
      13│   end(): mixed,
      14│   write(data: Chunk | BinaryChunk): void,
      15│   error(error: Error): void,
      16│   flush?: () => void,
      17│ };


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ packages/react-dom/src/server/ReactDOMFizzServerNode.js:393:35

Cannot call startFlowing with writable bound to destination because stream$Writable [1] is incompatible with
ReadableStreamController [2]. [incompatible-call]

     packages/react-dom/src/server/ReactDOMFizzServerNode.js
 [1] 384│       let writable: Writable;
        :
     390│               createFakeWritableFromReadableStreamController(controller);
     391│           },
     392│           pull: (controller): ?Promise<void> => {
     393│             startFlowing(request, writable);
     394│           },
     395│           cancel: (reason): ?Promise<void> => {
     396│             stopFlowing(request);

     packages/react-server/src/ReactServerStreamConfigBun.js
 [2]  12│ type BunReadableStreamController = ReadableStreamController & {


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ packages/react-dom/src/server/ReactDOMFizzServerNode.js:393:35

Cannot call startFlowing with writable bound to destination because inexact stream$Writable [1] is incompatible with
exact object type [2]. [incompatible-exact]

     packages/react-dom/src/server/ReactDOMFizzServerNode.js
 [1] 384│       let writable: Writable;
        :
     390│               createFakeWritableFromReadableStreamController(controller);
     391│           },
     392│           pull: (controller): ?Promise<void> => {
     393│             startFlowing(request, writable);
     394│           },
     395│           cancel: (reason): ?Promise<void> => {
     396│             stopFlowing(request);

     packages/react-server/src/ReactServerStreamConfigBun.js
 [2]  12│ type BunReadableStreamController = ReadableStreamController & {
      13│   end(): mixed,
      14│   write(data: Chunk | BinaryChunk): void,
      15│   error(error: Error): void,
      16│   flush?: () => void,
      17│ };



Found 10 errors
Flow failed for the dom-bun renderer
```


</details>

Code after:
/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

export * from './ReactDOMFizzServerBun.js';
export {
  renderToPipeableStream,
  resumeToPipeableStream,
  resume,
} from './ReactDOMFizzServerNode.js';
export {
  prerenderToNodeStream,
  prerender,
  resumeAndPrerenderToNodeStream,
  resumeAndPrerender,
} from './ReactDOMFizzStaticNode.js';