Skip to content

Commit

Permalink
Expose prerender() for SSG
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Oct 19, 2024
1 parent 1839e14 commit 6e896dc
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 14 deletions.
3 changes: 1 addition & 2 deletions packages/react-dom/src/__tests__/ReactDOMFizzStatic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ describe('ReactDOMFizzStatic', () => {
return readText(text);
}

// @gate experimental
it('should render a fully static document, send it and then hydrate it', async () => {
function App() {
return (
Expand All @@ -230,7 +229,7 @@ describe('ReactDOMFizzStatic', () => {

const result = await promise;

expect(result.postponed).toBe(null);
expect(result.postponed).toBe(gate(flags => flags.enableHalt || flags.enablePostpone) ? null : undefined);

await act(async () => {
result.prelude.pipe(writable);
Expand Down
15 changes: 11 additions & 4 deletions packages/react-dom/src/server/ReactDOMFizzStaticBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import {
createRootFormatContext,
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';

import {enablePostpone, enableHalt} from 'shared/ReactFeatureFlags';

import {ensureCorrectIsomorphicReactVersion} from '../shared/ensureCorrectIsomorphicReactVersion';
ensureCorrectIsomorphicReactVersion();

Expand Down Expand Up @@ -85,10 +87,15 @@ function prerender(
{highWaterMark: 0},
);

const result = {
postponed: getPostponedState(request),
prelude: stream,
};
const result: StaticResult =
enablePostpone || enableHalt
? {
postponed: getPostponedState(request),
prelude: stream,
}
: ({
prelude: stream,
}: any);
resolve(result);
}

Expand Down
15 changes: 11 additions & 4 deletions packages/react-dom/src/server/ReactDOMFizzStaticEdge.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import {
createRootFormatContext,
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';

import {enablePostpone, enableHalt} from 'shared/ReactFeatureFlags';

import {ensureCorrectIsomorphicReactVersion} from '../shared/ensureCorrectIsomorphicReactVersion';
ensureCorrectIsomorphicReactVersion();

Expand Down Expand Up @@ -85,10 +87,15 @@ function prerender(
{highWaterMark: 0},
);

const result = {
postponed: getPostponedState(request),
prelude: stream,
};
const result: StaticResult =
enablePostpone || enableHalt
? {
postponed: getPostponedState(request),
prelude: stream,
}
: ({
prelude: stream,
}: any);
resolve(result);
}

Expand Down
15 changes: 11 additions & 4 deletions packages/react-dom/src/server/ReactDOMFizzStaticNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import {
createRootFormatContext,
} from 'react-dom-bindings/src/server/ReactFizzConfigDOM';

import {enablePostpone, enableHalt} from 'shared/ReactFeatureFlags';

import {ensureCorrectIsomorphicReactVersion} from '../shared/ensureCorrectIsomorphicReactVersion';
ensureCorrectIsomorphicReactVersion();

Expand Down Expand Up @@ -94,10 +96,15 @@ function prerenderToNodeStream(
});
const writable = createFakeWritable(readable);

const result = {
postponed: getPostponedState(request),
prelude: readable,
};
const result: StaticResult =
enablePostpone || enableHalt
? {
postponed: getPostponedState(request),
prelude: readable,
}
: ({
prelude: readable,
}: any);
resolve(result);
}
const resumableState = createResumableState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
*/

export {renderToReadableStream, version} from './ReactDOMFizzServerBrowser.js';
export {prerender} from './ReactDOMFizzStaticBrowser.js';
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
*/

export {renderToReadableStream, version} from './ReactDOMFizzServerEdge.js';
export {prerender} from './ReactDOMFizzStaticEdge.js';
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
*/

export {renderToPipeableStream, version} from './ReactDOMFizzServerNode.js';
export {prerenderToNodeStream} from './ReactDOMFizzStaticNode.js';

0 comments on commit 6e896dc

Please sign in to comment.