Skip to content

Commit

Permalink
[Flight] Implement prerender
Browse files Browse the repository at this point in the history
Prerendering in flight is similar to prerendering in Fizz. Instead of receiving a result (the stream) immediately a promise is returned which resolves to the stream when the prerender is complete. The promise will reject if the flight render fatally errors otherwise it will resolve when the render is completed or is aborted.
  • Loading branch information
gnoff committed Aug 15, 2024
1 parent 986778e commit f77261b
Show file tree
Hide file tree
Showing 45 changed files with 544 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/react-server-dom-esm/npm/static.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

throw new Error(
'The React Server Writer cannot be used outside a react-server environment. ' +
'You must configure Node.js using the `--conditions react-server` flag.'
);
12 changes: 12 additions & 0 deletions packages/react-server-dom-esm/npm/static.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var s;
if (process.env.NODE_ENV === 'production') {
s = require('./cjs/react-server-dom-esm-server.node.production.js');
} else {
s = require('./cjs/react-server-dom-esm-server.node.development.js');
}

if (s.prerenderToNodeStream) {
exports.prerenderToNodeStream = s.prerenderToNodeStream;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

export {
renderToPipeableStream,
prerenderToNodeStream,
decodeReplyFromBusboy,
decodeReply,
decodeAction,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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 {
renderToPipeableStream,
decodeReplyFromBusboy,
decodeReply,
decodeAction,
decodeFormState,
registerServerReference,
registerClientReference,
createTemporaryReferenceSet,
} from './ReactFlightDOMServerNode';
13 changes: 13 additions & 0 deletions packages/react-server-dom-esm/static.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* 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
*/

throw new Error(
'The React Server cannot be used outside a react-server environment. ' +
'You must configure Node.js using the `--conditions react-server` flag.',
);
10 changes: 10 additions & 0 deletions packages/react-server-dom-esm/static.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* 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 {prerenderToNodeStream} from './src/server/react-flight-dom-server.node';
12 changes: 12 additions & 0 deletions packages/react-server-dom-turbopack/npm/static.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var s;
if (process.env.NODE_ENV === 'production') {
s = require('./cjs/react-server-dom-turbopack-server.browser.production.js');
} else {
s = require('./cjs/react-server-dom-turbopack-server.browser.development.js');
}

if (s.prerender) {
exports.prerender = s.prerender;
}
12 changes: 12 additions & 0 deletions packages/react-server-dom-turbopack/npm/static.edge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var s;
if (process.env.NODE_ENV === 'production') {
s = require('./cjs/react-server-dom-turbopack-server.edge.production.js');
} else {
s = require('./cjs/react-server-dom-turbopack-server.edge.development.js');
}

if (s.prerender) {
exports.prerender = s.prerender;
}
6 changes: 6 additions & 0 deletions packages/react-server-dom-turbopack/npm/static.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

throw new Error(
'The React Server Writer cannot be used outside a react-server environment. ' +
'You must configure Node.js using the `--conditions react-server` flag.'
);
12 changes: 12 additions & 0 deletions packages/react-server-dom-turbopack/npm/static.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var s;
if (process.env.NODE_ENV === 'production') {
s = require('./cjs/react-server-dom-turbopack-server.node.production.js');
} else {
s = require('./cjs/react-server-dom-turbopack-server.node.development.js');
}

if (s.prerenderToNodeStream) {
exports.prerenderToNodeStream = s.prerenderToNodeStream;
}
12 changes: 12 additions & 0 deletions packages/react-server-dom-turbopack/npm/static.node.unbundled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var s;
if (process.env.NODE_ENV === 'production') {
s = require('./cjs/react-server-dom-turbopack-server.node.unbundled.production.js');
} else {
s = require('./cjs/react-server-dom-turbopack-server.node.unbundled.development.js');
}

if (s.prerenderToNodeStream) {
exports.prerenderToNodeStream = s.prerenderToNodeStream;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

export {
renderToReadableStream,
prerender,
decodeReply,
decodeAction,
decodeFormState,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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 {
renderToReadableStream,
decodeReply,
decodeAction,
decodeFormState,
registerServerReference,
registerClientReference,
createClientModuleProxy,
createTemporaryReferenceSet,
} from './ReactFlightDOMServerBrowser';
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

export {
renderToReadableStream,
prerender,
decodeReply,
decodeAction,
decodeFormState,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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 {
renderToReadableStream,
decodeReply,
decodeAction,
decodeFormState,
registerServerReference,
registerClientReference,
createClientModuleProxy,
createTemporaryReferenceSet,
} from './ReactFlightDOMServerEdge';
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

export {
renderToPipeableStream,
prerenderToNodeStream,
decodeReplyFromBusboy,
decodeReply,
decodeAction,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* 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 {
renderToPipeableStream,
decodeReplyFromBusboy,
decodeReply,
decodeAction,
decodeFormState,
registerServerReference,
registerClientReference,
createClientModuleProxy,
createTemporaryReferenceSet,
} from './ReactFlightDOMServerNode';
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

export {
renderToPipeableStream,
prerenderToNodeStream,
decodeReplyFromBusboy,
decodeReply,
decodeAction,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* 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 {
renderToPipeableStream,
decodeReplyFromBusboy,
decodeReply,
decodeAction,
decodeFormState,
registerServerReference,
registerClientReference,
createClientModuleProxy,
createTemporaryReferenceSet,
} from './ReactFlightDOMServerNode';
10 changes: 10 additions & 0 deletions packages/react-server-dom-turbopack/static.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* 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 {prerender} from './src/server/react-flight-dom-server.browser';
10 changes: 10 additions & 0 deletions packages/react-server-dom-turbopack/static.edge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* 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 {prerender} from './src/server/react-flight-dom-server.edge';
13 changes: 13 additions & 0 deletions packages/react-server-dom-turbopack/static.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* 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
*/

throw new Error(
'The React Server cannot be used outside a react-server environment. ' +
'You must configure Node.js using the `--conditions react-server` flag.',
);
10 changes: 10 additions & 0 deletions packages/react-server-dom-turbopack/static.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* 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 {prerenderToNodeStream} from './src/server/react-flight-dom-server.node';
10 changes: 10 additions & 0 deletions packages/react-server-dom-turbopack/static.node.unbundled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* 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 {prerenderToNodeStream} from './src/server/react-flight-dom-server.node.unbundled';
12 changes: 12 additions & 0 deletions packages/react-server-dom-webpack/npm/static.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var s;
if (process.env.NODE_ENV === 'production') {
s = require('./cjs/react-server-dom-webpack-server.browser.production.js');
} else {
s = require('./cjs/react-server-dom-webpack-server.browser.development.js');
}

if (s.prerender) {
exports.prerender = s.prerender;
}
12 changes: 12 additions & 0 deletions packages/react-server-dom-webpack/npm/static.edge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var s;
if (process.env.NODE_ENV === 'production') {
s = require('./cjs/react-server-dom-webpack-server.edge.production.js');
} else {
s = require('./cjs/react-server-dom-webpack-server.edge.development.js');
}

if (s.prerender) {
exports.prerender = s.prerender;
}
6 changes: 6 additions & 0 deletions packages/react-server-dom-webpack/npm/static.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

throw new Error(
'The React Server Writer cannot be used outside a react-server environment. ' +
'You must configure Node.js using the `--conditions react-server` flag.'
);
12 changes: 12 additions & 0 deletions packages/react-server-dom-webpack/npm/static.node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var s;
if (process.env.NODE_ENV === 'production') {
s = require('./cjs/react-server-dom-webpack-server.node.production.js');
} else {
s = require('./cjs/react-server-dom-webpack-server.node.development.js');
}

if (s.prerenderToNodeStream) {
exports.prerenderToNodeStream = s.prerenderToNodeStream;
}
12 changes: 12 additions & 0 deletions packages/react-server-dom-webpack/npm/static.node.unbundled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var s;
if (process.env.NODE_ENV === 'production') {
s = require('./cjs/react-server-dom-webpack-server.node.unbundled.production.js');
} else {
s = require('./cjs/react-server-dom-webpack-server.node.unbundled.development.js');
}

if (s.prerenderToNodeStream) {
exports.prerenderToNodeStream = s.prerenderToNodeStream;
}
Loading

0 comments on commit f77261b

Please sign in to comment.