Skip to content

Commit 2f41c7d

Browse files
committed
moved cacheStream and renderToNodeStream logic out from index.js to modifiedReact file
1 parent 4c1e134 commit 2f41c7d

File tree

3 files changed

+44
-20
lines changed

3 files changed

+44
-20
lines changed

SSRtest/ModifiedReact.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,7 +2713,7 @@ var ReactMarkupReadableStream = function (_Readable) {
27132713
*/
27142714

27152715

2716-
function renderToNodeStream(element, cache, streamingStart, memLife=0) {
2716+
function originalRenderToNodeStream(element, cache, streamingStart, memLife=0) {
27172717
return new ReactMarkupReadableStream(
27182718
element,
27192719
false,
@@ -2806,15 +2806,37 @@ class ComponentCache {
28062806
}
28072807

28082808
}
2809-
2809+
2810+
function renderToNodeStream(compo, cache, res){
2811+
2812+
const htmlStart =
2813+
'<html><head><title>Page</title></head><body><div id="react-root">';
2814+
2815+
const htmlEnd = "</div></body></html>";
2816+
2817+
const streamingStart = {
2818+
sliceStartCount: htmlStart.length,
2819+
}
2820+
2821+
const cacheStream = createCacheStream(cache, streamingStart);
2822+
cacheStream.pipe(res);
2823+
cacheStream.write(htmlStart);
2824+
2825+
const stream = originalRenderToNodeStream(compo, cache, streamingStart);
2826+
stream.pipe(cacheStream, { end: false });
2827+
stream.on("end", () => {
2828+
cacheStream.end(htmlEnd);
2829+
});
2830+
2831+
}
28102832
// Note: when changing this, also consider https://github.com/facebook/react/issues/11526
28112833
var ReactDOMServerNode = {
28122834
renderToString: renderToString,
28132835
renderToStaticMarkup: renderToStaticMarkup,
28142836
renderToNodeStream: renderToNodeStream,
28152837
renderToStaticNodeStream: renderToStaticNodeStream,
28162838
ComponentCache: ComponentCache,
2817-
createCacheStream: createCacheStream,
2839+
// createCacheStream: createCacheStream,
28182840
version: ReactVersion
28192841
};
28202842

SSRtest/src/server/index.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,33 @@ const cache = new ReactCC.ComponentCache();
1616

1717
// Force NodeStream
1818

19-
const htmlStart =
20-
'<html><head><title>Page</title></head><body><div id="react-root">';
21-
const htmlEnd = "</div></body></html>";
19+
// const htmlStart =
20+
// '<html><head><title>Page</title></head><body><div id="react-root">';
21+
// const htmlEnd = "</div></body></html>";
2222

2323

24-
const streamingStart = {
25-
sliceStartCount: htmlStart.length,
26-
};
24+
// const streamingStart = {
25+
// sliceStartCount: htmlStart.length,
26+
// };
2727
/**
2828
* @param clientStats Parameter passed by hot server middleware
2929
*/
3030
export default ({ clientStats }) => async (req, res) => {
3131
// Need To Come back To If Statement
32-
if(false){
33-
const cacheStream = ReactCC.createCacheStream(cache, streamingStart);
34-
cacheStream.pipe(res);
35-
cacheStream.write(htmlStart);
32+
if(true){
33+
ReactCC.renderToNodeStream(<App/>, cache, res);
34+
// const cacheStream = ReactCC.createCacheStream(cache, streamingStart);
35+
// cacheStream.pipe(res);
36+
// cacheStream.write(htmlStart);
37+
38+
// const stream = ReactCC.renderToNodeStream(<App />, cache, streamingStart);
39+
// stream.pipe(cacheStream, { end: false });
40+
// stream.on("end", () => {
41+
// cacheStream.end(htmlEnd);
42+
// });
3643

37-
const stream = ReactCC.renderToNodeStream(<App />, cache, streamingStart);
38-
stream.pipe(cacheStream, { end: false });
39-
stream.on("end", () => {
40-
cacheStream.end(htmlEnd);
41-
});
4244
}
43-
else if (true){
45+
else if (false){
4446
const app = <App />;
4547
const start_cached = process.hrtime();
4648

SSRtest/src/shared/List.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class List extends Component {
1212
let bunchOfProducts = [];
1313
const templatizedProps = ["name", "description", "price"];
1414
for (let i=0; i<100; i++) {
15-
bunchOfProducts.push(<ProductInfo key={i} name={`Thing ${i}`} description="This product is awesome!" price={i * 10} nonTemplatized="THIS TEXT SHOULD NEVER CHANGE" cache templatized={templatizedProps}/>);
15+
bunchOfProducts.push(<ProductInfo key={i} name={`Thing ${i}`} description="This product is awesome!" price={i * 10} nonTemplatized="THIS TEXT SHOULD NEVER CHANGE" cache />);
1616
}
1717
return (
1818
<div>

0 commit comments

Comments
 (0)