Skip to content

Commit 0438912

Browse files
committed
fix partialrenderer variants
1 parent 2e78547 commit 0438912

File tree

4 files changed

+130
-90
lines changed

4 files changed

+130
-90
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
export {
11+
renderToString,
12+
renderToStaticMarkup,
13+
version,
14+
} from './ReactDOMServerLegacyPartialRendererBrowser';
15+
16+
export {
17+
renderToNodeStream,
18+
renderToStaticNodeStream,
19+
} from './ReactDOMLegacyServerNodeStream';

packages/react-dom/src/server/ReactDOMLegacyServerNode.js

Lines changed: 4 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -9,102 +9,16 @@
99

1010
import type {ReactNodeList} from 'shared/ReactTypes';
1111

12-
import type {Request} from 'react-server/src/ReactFizzServer';
13-
14-
import {
15-
createRequest,
16-
startWork,
17-
startFlowing,
18-
abort,
19-
} from 'react-server/src/ReactFizzServer';
20-
21-
import {
22-
createResponseState,
23-
createRootFormatContext,
24-
} from './ReactDOMServerLegacyFormatConfig';
25-
2612
import {version, renderToStringImpl} from './ReactDOMLegacyServerImpl';
27-
28-
import {Readable} from 'stream';
13+
import {
14+
renderToNodeStream,
15+
renderToStaticNodeStream,
16+
} from './ReactDOMLegacyServerNodeStream';
2917

3018
type ServerOptions = {
3119
identifierPrefix?: string,
3220
};
3321

34-
class ReactMarkupReadableStream extends Readable {
35-
request: Request;
36-
startedFlowing: boolean;
37-
constructor() {
38-
// Calls the stream.Readable(options) constructor. Consider exposing built-in
39-
// features like highWaterMark in the future.
40-
super({});
41-
this.request = (null: any);
42-
this.startedFlowing = false;
43-
}
44-
45-
_destroy(err, callback) {
46-
abort(this.request);
47-
// $FlowFixMe: The type definition for the callback should allow undefined and null.
48-
callback(err);
49-
}
50-
51-
_read(size) {
52-
if (this.startedFlowing) {
53-
startFlowing(this.request, this);
54-
}
55-
}
56-
}
57-
58-
function onError() {
59-
// Non-fatal errors are ignored.
60-
}
61-
62-
function renderToNodeStreamImpl(
63-
children: ReactNodeList,
64-
options: void | ServerOptions,
65-
generateStaticMarkup: boolean,
66-
): Readable {
67-
function onAllReady() {
68-
// We wait until everything has loaded before starting to write.
69-
// That way we only end up with fully resolved HTML even if we suspend.
70-
destination.startedFlowing = true;
71-
startFlowing(request, destination);
72-
}
73-
const destination = new ReactMarkupReadableStream();
74-
const request = createRequest(
75-
children,
76-
createResponseState(false, options ? options.identifierPrefix : undefined),
77-
createRootFormatContext(),
78-
Infinity,
79-
onError,
80-
onAllReady,
81-
undefined,
82-
undefined,
83-
);
84-
destination.request = request;
85-
startWork(request);
86-
return destination;
87-
}
88-
89-
function renderToNodeStream(
90-
children: ReactNodeList,
91-
options?: ServerOptions,
92-
): Readable {
93-
if (__DEV__) {
94-
console.error(
95-
'renderToNodeStream is deprecated. Use renderToPipeableStream instead.',
96-
);
97-
}
98-
return renderToNodeStreamImpl(children, options, false);
99-
}
100-
101-
function renderToStaticNodeStream(
102-
children: ReactNodeList,
103-
options?: ServerOptions,
104-
): Readable {
105-
return renderToNodeStreamImpl(children, options, true);
106-
}
107-
10822
function renderToString(
10923
children: ReactNodeList,
11024
options?: ServerOptions,
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import type {ReactNodeList} from 'shared/ReactTypes';
11+
12+
import type {Request} from 'react-server/src/ReactFizzServer';
13+
14+
import {
15+
createRequest,
16+
startWork,
17+
startFlowing,
18+
abort,
19+
} from 'react-server/src/ReactFizzServer';
20+
21+
import {
22+
createResponseState,
23+
createRootFormatContext,
24+
} from './ReactDOMServerLegacyFormatConfig';
25+
26+
import {Readable} from 'stream';
27+
28+
type ServerOptions = {
29+
identifierPrefix?: string,
30+
};
31+
32+
class ReactMarkupReadableStream extends Readable {
33+
request: Request;
34+
startedFlowing: boolean;
35+
constructor() {
36+
// Calls the stream.Readable(options) constructor. Consider exposing built-in
37+
// features like highWaterMark in the future.
38+
super({});
39+
this.request = (null: any);
40+
this.startedFlowing = false;
41+
}
42+
43+
_destroy(err, callback) {
44+
abort(this.request);
45+
// $FlowFixMe: The type definition for the callback should allow undefined and null.
46+
callback(err);
47+
}
48+
49+
_read(size) {
50+
if (this.startedFlowing) {
51+
startFlowing(this.request, this);
52+
}
53+
}
54+
}
55+
56+
function onError() {
57+
// Non-fatal errors are ignored.
58+
}
59+
60+
function renderToNodeStreamImpl(
61+
children: ReactNodeList,
62+
options: void | ServerOptions,
63+
generateStaticMarkup: boolean,
64+
): Readable {
65+
function onAllReady() {
66+
// We wait until everything has loaded before starting to write.
67+
// That way we only end up with fully resolved HTML even if we suspend.
68+
destination.startedFlowing = true;
69+
startFlowing(request, destination);
70+
}
71+
const destination = new ReactMarkupReadableStream();
72+
const request = createRequest(
73+
children,
74+
createResponseState(false, options ? options.identifierPrefix : undefined),
75+
createRootFormatContext(),
76+
Infinity,
77+
onError,
78+
onAllReady,
79+
undefined,
80+
undefined,
81+
);
82+
destination.request = request;
83+
startWork(request);
84+
return destination;
85+
}
86+
87+
function renderToNodeStream(
88+
children: ReactNodeList,
89+
options?: ServerOptions,
90+
): Readable {
91+
if (__DEV__) {
92+
console.error(
93+
'renderToNodeStream is deprecated. Use renderToPipeableStream instead.',
94+
);
95+
}
96+
return renderToNodeStreamImpl(children, options, false);
97+
}
98+
99+
function renderToStaticNodeStream(
100+
children: ReactNodeList,
101+
options?: ServerOptions,
102+
): Readable {
103+
return renderToNodeStreamImpl(children, options, true);
104+
}
105+
106+
export {renderToNodeStream, renderToStaticNodeStream};

scripts/shared/inlinedHostConfigs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ module.exports = [
7272
'react-dom/src/server/ReactDOMLegacyServerImpl.js', // not an entrypoint, but only usable in *Brower and *Node files
7373
'react-dom/src/server/ReactDOMLegacyServerBrowser.js', // react-dom/server.browser
7474
'react-dom/src/server/ReactDOMLegacyServerNode.js', // react-dom/server.node
75+
'react-dom/src/server/ReactDOMLegacyServerNodeStream.js', // file indirection to support partial forking of some methods in *Node
7576
'react-client/src/ReactFlightClientStream.js', // We can only type check this in streaming configurations.
7677
],
7778
isFlowTyped: true,

0 commit comments

Comments
 (0)