Skip to content

Commit

Permalink
Rename to renderToPipeableStream
Browse files Browse the repository at this point in the history
This mimics the renderToReadableStream API for the browser.
  • Loading branch information
sebmarkbage committed Oct 6, 2021
1 parent 460b829 commit a127ca0
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 60 deletions.
7 changes: 5 additions & 2 deletions fixtures/flight/server/handler.server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const {renderToNodePipe} = require('react-server-dom-webpack/writer');
const {renderToPipeableStream} = require('react-server-dom-webpack/writer');
const {readFile} = require('fs');
const {resolve} = require('path');
const React = require('react');
Expand All @@ -20,7 +20,10 @@ module.exports = function(req, res) {
const App = m.default.default || m.default;
res.setHeader('Access-Control-Allow-Origin', '*');
const moduleMap = JSON.parse(data);
const {pipe} = renderToNodePipe(React.createElement(App), moduleMap);
const {pipe} = renderToPipeableStream(
React.createElement(App),
moduleMap
);
pipe(res);
}
);
Expand Down
4 changes: 2 additions & 2 deletions fixtures/ssr/server/render.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {renderToNodePipe} from 'react-dom/server';
import {renderToPipeableStream} from 'react-dom/server';

import App from '../src/components/App';

Expand All @@ -20,7 +20,7 @@ export default function render(url, res) {
console.error('Fatal', error);
});
let didError = false;
const {pipe, abort} = renderToNodePipe(<App assets={assets} />, {
const {pipe, abort} = renderToPipeableStream(<App assets={assets} />, {
onCompleteShell() {
// If something errored before we started streaming, we set the error code appropriately.
res.statusCode = didError ? 500 : 200;
Expand Down
4 changes: 2 additions & 2 deletions fixtures/ssr2/server/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import * as React from 'react';
// import {renderToString} from 'react-dom/server';
import {renderToNodePipe} from 'react-dom/server';
import {renderToPipeableStream} from 'react-dom/server';
import App from '../src/App';
import {DataProvider} from '../src/data';
import {API_DELAY, ABORT_DELAY} from './delays';
Expand Down Expand Up @@ -37,7 +37,7 @@ module.exports = function render(url, res) {
});
let didError = false;
const data = createServerData();
const {pipe, abort} = renderToNodePipe(
const {pipe, abort} = renderToPipeableStream(
<DataProvider data={data}>
<App assets={assets} />
</DataProvider>,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/npm/server.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ exports.renderToString = l.renderToString;
exports.renderToStaticMarkup = l.renderToStaticMarkup;
exports.renderToNodeStream = l.renderToNodeStream;
exports.renderToStaticNodeStream = l.renderToStaticNodeStream;
exports.renderToNodePipe = s.renderToNodePipe;
exports.renderToPipeableStream = s.renderToPipeableStream;
4 changes: 2 additions & 2 deletions packages/react-dom/server.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export function renderToStaticNodeStream() {
);
}

export function renderToNodePipe() {
return require('./src/server/ReactDOMFizzServerNode').renderToNodePipe.apply(
export function renderToPipeableStream() {
return require('./src/server/ReactDOMFizzServerNode').renderToPipeableStream.apply(
this,
arguments,
);
Expand Down
52 changes: 26 additions & 26 deletions packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ describe('ReactDOMFizzServer', () => {
};

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<div>
<div>
<Suspense fallback={<Text text="Loading..." />}>
Expand Down Expand Up @@ -303,7 +303,7 @@ describe('ReactDOMFizzServer', () => {
}

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<App isClient={false} />,

{
Expand Down Expand Up @@ -355,7 +355,7 @@ describe('ReactDOMFizzServer', () => {
});

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<div>
<Suspense fallback={<Text text="Loading..." />}>
{lazyElement}
Expand Down Expand Up @@ -394,7 +394,7 @@ describe('ReactDOMFizzServer', () => {
}

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<App isClient={false} />,

{
Expand Down Expand Up @@ -439,7 +439,7 @@ describe('ReactDOMFizzServer', () => {
// @gate experimental
it('should asynchronously load the suspense boundary', async () => {
await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<div>
<Suspense fallback={<Text text="Loading..." />}>
<AsyncText text="Hello World" />
Expand Down Expand Up @@ -472,7 +472,7 @@ describe('ReactDOMFizzServer', () => {
}

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(<App />);
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(<App />);
pipe(writable);
});

Expand Down Expand Up @@ -544,7 +544,7 @@ describe('ReactDOMFizzServer', () => {

// We originally suspend the boundary and start streaming the loading state.
await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<App />,

{
Expand Down Expand Up @@ -627,7 +627,7 @@ describe('ReactDOMFizzServer', () => {

// We originally suspend the boundary and start streaming the loading state.
await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<App showMore={false} />,
);
pipe(writable);
Expand Down Expand Up @@ -694,7 +694,7 @@ describe('ReactDOMFizzServer', () => {

let controls;
await act(async () => {
controls = ReactDOMFizzServer.renderToNodePipe(<App />);
controls = ReactDOMFizzServer.renderToPipeableStream(<App />);
controls.pipe(writable);
});

Expand Down Expand Up @@ -746,7 +746,7 @@ describe('ReactDOMFizzServer', () => {
};

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
// We use two nested boundaries to flush out coverage of an old reentrancy bug.
<Suspense fallback="Loading...">
<Suspense fallback={<Text text="Loading A..." />}>
Expand All @@ -770,7 +770,7 @@ describe('ReactDOMFizzServer', () => {
});

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<Suspense fallback={<Text text="Loading B..." />}>
<Text text="This will show B: " />
<div>
Expand Down Expand Up @@ -867,7 +867,7 @@ describe('ReactDOMFizzServer', () => {
}

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(<App />);
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(<App />);
pipe(writable);
});

Expand Down Expand Up @@ -955,7 +955,7 @@ describe('ReactDOMFizzServer', () => {
}

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(<App />);
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(<App />);
pipe(writable);
});

Expand Down Expand Up @@ -1009,7 +1009,7 @@ describe('ReactDOMFizzServer', () => {
}

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<App />,

{
Expand Down Expand Up @@ -1096,7 +1096,7 @@ describe('ReactDOMFizzServer', () => {

try {
await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(<A />);
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(<A />);
pipe(writable);
});

Expand Down Expand Up @@ -1195,7 +1195,7 @@ describe('ReactDOMFizzServer', () => {
}

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<TestProvider ctx="A">
<div>
<Suspense fallback={[<Text text="Loading: " />, <TestConsumer />]}>
Expand Down Expand Up @@ -1253,7 +1253,7 @@ describe('ReactDOMFizzServer', () => {
}

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<div>
<PrintA />
<div>
Expand Down Expand Up @@ -1315,7 +1315,7 @@ describe('ReactDOMFizzServer', () => {

const loggedErrors = [];
await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<div>
<PrintA />
<div>
Expand Down Expand Up @@ -1376,7 +1376,7 @@ describe('ReactDOMFizzServer', () => {
const loggedErrors = [];
let controls;
await act(async () => {
controls = ReactDOMFizzServer.renderToNodePipe(
controls = ReactDOMFizzServer.renderToPipeableStream(
<App isClient={false} />,

{
Expand Down Expand Up @@ -1436,7 +1436,7 @@ describe('ReactDOMFizzServer', () => {
// @gate experimental
it('should be able to abort the fallback if the main content finishes first', async () => {
await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<Suspense fallback={<Text text="Loading Outer" />}>
<div>
<Suspense
Expand Down Expand Up @@ -1533,7 +1533,7 @@ describe('ReactDOMFizzServer', () => {
await jest.runAllTimers();

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<App isClient={false} />,
);
pipe(writable);
Expand Down Expand Up @@ -1647,7 +1647,7 @@ describe('ReactDOMFizzServer', () => {

const loggedErrors = [];
await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<Suspense fallback="Loading...">
<App />
</Suspense>,
Expand Down Expand Up @@ -1730,7 +1730,7 @@ describe('ReactDOMFizzServer', () => {

const loggedErrors = [];
await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(
<Suspense fallback="Loading...">
<App />
</Suspense>,
Expand Down Expand Up @@ -1816,7 +1816,7 @@ describe('ReactDOMFizzServer', () => {
}

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(<App />);
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(<App />);
pipe(writable);
});
expect(Scheduler).toHaveYielded(['Yay!']);
Expand Down Expand Up @@ -1897,7 +1897,7 @@ describe('ReactDOMFizzServer', () => {
}

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(<App />);
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(<App />);
pipe(writable);
});
expect(Scheduler).toHaveYielded(['Yay!']);
Expand Down Expand Up @@ -1969,7 +1969,7 @@ describe('ReactDOMFizzServer', () => {
}

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToNodePipe(<App />);
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(<App />);
pipe(writable);
});
expect(Scheduler).toHaveYielded(['Yay!']);
Expand Down
Loading

0 comments on commit a127ca0

Please sign in to comment.