Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 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,10 @@ if (process.env.NODE_ENV === 'production') {

exports.version = b.version;
exports.renderToReadableStream = b.renderToReadableStream;
exports.renderToPipeableStream = b.renderToPipeableStream;
if (b.resumeToPipeableStream) {
exports.resumeToPipeableStream = b.resumeToPipeableStream;
}
if (b.resume) {
exports.resume = b.resume;
}
Expand Down
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,
);
}
10 changes: 10 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,13 @@
*/

export * from './ReactDOMFizzServerBun.js';
export {
renderToPipeableStream,
resumeToPipeableStream,
} from './ReactDOMFizzServerNode.js';
export {
prerenderToNodeStream,
prerender,
resumeAndPrerenderToNodeStream,
resumeAndPrerender,
} from './ReactDOMFizzStaticNode.js';
2 changes: 2 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,5 @@
*/

export {renderToReadableStream, version} from './ReactDOMFizzServerBun.js';
export {renderToPipeableStream} from './ReactDOMFizzServerNode.js';
export {prerenderToNodeStream, prerender} from './ReactDOMFizzStaticNode.js';
28 changes: 25 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,22 +97,33 @@ 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
// case to begin with. It's even less common to run this in an older environment.
// Even then, this is not where errors are supposed to happen and they get reported
// to a global callback in addition to this anyway. So it's fine just to close this.
// $FlowFixMe[incompatible-call]
destination.close();
}
}

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', 'util', 'react-dom'],
},

/******* 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