Skip to content
2 changes: 2 additions & 0 deletions packages/react-dom/npm/server.bun.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ if (process.env.NODE_ENV === 'production') {

exports.version = b.version;
exports.renderToReadableStream = b.renderToReadableStream;
exports.renderToPipeableStream = b.renderToPipeableStream;
exports.resumeToPipeableStream = b.resumeToPipeableStream;
exports.resume = b.resume;
exports.renderToString = l.renderToString;
exports.renderToStaticMarkup = l.renderToStaticMarkup;
14 changes: 14 additions & 0 deletions packages/react-dom/server.bun.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,17 @@ export function resume() {
arguments,
);
}

export function renderToPipeableStream() {
return require('./src/server/react-dom-server.bun').renderToPipeableStream.apply(
this,
arguments,
);
}

export function resumeToPipeableStream() {
return require('./src/server/react-dom-server.bun').resumeToPipeableStream.apply(
this,
arguments,
);
}
11 changes: 11 additions & 0 deletions packages/react-dom/src/server/react-dom-server.bun.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@
*/

export * from './ReactDOMFizzServerBun.js';
export {
renderToPipeableStream,
resumeToPipeableStream,
resume,
} from './ReactDOMFizzServerNode.js';
export {
prerenderToNodeStream,
prerender,
resumeAndPrerenderToNodeStream,
resumeAndPrerender,
} from './ReactDOMFizzStaticNode.js';
11 changes: 11 additions & 0 deletions packages/react-dom/src/server/react-dom-server.bun.stable.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@
*/

export {renderToReadableStream, version} from './ReactDOMFizzServerBun.js';
export {
renderToPipeableStream,
resume,
resumeToPipeableStream,
} from './ReactDOMFizzServerNode.js';
export {
prerenderToNodeStream,
prerender,
resumeAndPrerenderToNodeStream,
resumeAndPrerender,
} from './ReactDOMFizzStaticNode.js';
27 changes: 24 additions & 3 deletions packages/react-server/src/ReactServerStreamConfigBun.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@

/* global Bun */

import type {Writable} from 'stream';

type BunReadableStreamController = ReadableStreamController & {
end(): mixed,
write(data: Chunk | BinaryChunk): void,
error(error: Error): void,
flush?: () => void,
};
export type Destination = BunReadableStreamController;

interface MightBeFlushable {
flush?: () => void;
}

export type Destination =
| BunReadableStreamController
| (Writable & MightBeFlushable);

export type PrecomputedChunk = string;
export opaque type Chunk = string;
Expand Down Expand Up @@ -46,13 +55,15 @@ export function writeChunk(
return;
}

// $FlowFixMe[incompatible-call]: write() is compatible with both types in Bun
destination.write(chunk);
}

export function writeChunkAndReturn(
destination: Destination,
chunk: PrecomputedChunk | Chunk | BinaryChunk,
): boolean {
// $FlowFixMe[incompatible-call]: write() is compatible with both types in Bun
return !!destination.write(chunk);
}

Expand Down Expand Up @@ -86,11 +97,21 @@ export function byteLengthOfBinaryChunk(chunk: BinaryChunk): number {
}

export function closeWithError(destination: Destination, error: mixed): void {
// $FlowFixMe[incompatible-use]
// $FlowFixMe[method-unbinding]
if (typeof destination.error === 'function') {
// $FlowFixMe[incompatible-call]: This is an Error object or the destination accepts other types.
destination.error(error);
} else {

// $FlowFixMe[incompatible-use]
// $FlowFixMe[method-unbinding]
} else if (typeof destination.destroy === 'function') {
// $FlowFixMe[incompatible-call]: This is an Error object or the destination accepts other types.
destination.destroy(error);

// $FlowFixMe[incompatible-use]
// $FlowFixMe[method-unbinding]
} else if (typeof destination.close === 'function') {
// Earlier implementations doesn't support this method. In that environment you're
// supposed to throw from a promise returned but we don't return a promise in our
// approach. We could fork this implementation but this is environment is an edge
Expand All @@ -101,7 +122,7 @@ export function closeWithError(destination: Destination, error: mixed): void {
}
}

export function createFastHash(input: string): string | number {
export function createFastHash(input: string): number {
return Bun.hash(input);
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/rollup/bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ const bundles = [
global: 'ReactDOMServer',
minifyWithProdErrorCodes: false,
wrapWithModuleBoundaries: false,
externals: ['react', 'react-dom'],
externals: ['react', 'react-dom', 'crypto', 'stream', 'util'],
},

/******* React DOM Fizz Server External Runtime *******/
Expand Down
2 changes: 2 additions & 0 deletions scripts/shared/inlinedHostConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ module.exports = [
'react-dom/server.bun',
'react-dom/src/server/react-dom-server.bun',
'react-dom/src/server/ReactDOMFizzServerBun.js',
'react-dom/src/server/ReactDOMFizzServerNode.js',
'react-dom/src/server/ReactDOMFizzStaticNode.js',
'react-dom-bindings',
'react-dom-bindings/src/server/ReactDOMFlightServerHostDispatcher.js',
'react-dom-bindings/src/server/ReactFlightServerConfigDOM.js',
Expand Down
Loading