Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 47515ec

Browse files
extracted streaming logic out from modified file
1 parent 2f41c7d commit 47515ec

File tree

3 files changed

+46
-22
lines changed

3 files changed

+46
-22
lines changed

‎SSRtest/ModifiedReact.js‎

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

27152715

2716-
function originalRenderToNodeStream(element, cache, streamingStart, memLife=0) {
2716+
function renderToNodeStream(element, cache, streamingStart, memLife=0) {
27172717
return new ReactMarkupReadableStream(
27182718
element,
27192719
false,
@@ -2807,28 +2807,28 @@ class ComponentCache {
28072807

28082808
}
28092809

2810-
function renderToNodeStream(compo, cache, res){
2810+
// function renderToNodeStream(compo, cache, res){
28112811

2812-
const htmlStart =
2813-
'<html><head><title>Page</title></head><body><div id="react-root">';
2812+
// const htmlStart =
2813+
// '<html><head><title>Page</title></head><body><div id="react-root">';
28142814

2815-
const htmlEnd = "</div></body></html>";
2815+
// const htmlEnd = "</div></body></html>";
28162816

2817-
const streamingStart = {
2818-
sliceStartCount: htmlStart.length,
2819-
}
2817+
// const streamingStart = {
2818+
// sliceStartCount: htmlStart.length,
2819+
// }
28202820

2821-
const cacheStream = createCacheStream(cache, streamingStart);
2822-
cacheStream.pipe(res);
2823-
cacheStream.write(htmlStart);
2821+
// const cacheStream = createCacheStream(cache, streamingStart);
2822+
// cacheStream.pipe(res);
2823+
// cacheStream.write(htmlStart);
28242824

2825-
const stream = originalRenderToNodeStream(compo, cache, streamingStart);
2826-
stream.pipe(cacheStream, { end: false });
2827-
stream.on("end", () => {
2828-
cacheStream.end(htmlEnd);
2829-
});
2825+
// const stream = originalRenderToNodeStream(compo, cache, streamingStart);
2826+
// stream.pipe(cacheStream, { end: false });
2827+
// stream.on("end", () => {
2828+
// cacheStream.end(htmlEnd);
2829+
// });
28302830

2831-
}
2831+
// }
28322832
// Note: when changing this, also consider https://github.com/facebook/react/issues/11526
28332833
var ReactDOMServerNode = {
28342834
renderToString: renderToString,

‎SSRtest/src/server/index.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React from 'react';
44
import ReactCC from '../../ModifiedReact';
55
import { flushChunkNames } from 'react-universal-component/server';
66
import flushChunks from 'webpack-flush-chunks';
7-
7+
importzNodeStreamfrom"./zNodeStream.js";
88
import App from '../shared/App';
99

1010
// can pass in max-size, otherwise defaults to 1 million
@@ -30,7 +30,7 @@ const cache = new ReactCC.ComponentCache();
3030
export default ({ clientStats }) => async (req, res) => {
3131
// Need To Come back To If Statement
3232
if(true){
33-
ReactCC.renderToNodeStream(<App/>, cache, res);
33+
zNodeStream(<App/>,false, cache, res);
3434
// const cacheStream = ReactCC.createCacheStream(cache, streamingStart);
3535
// cacheStream.pipe(res);
3636
// cacheStream.write(htmlStart);

‎SSRtest/src/server/cacheStream.js‎ renamed to ‎SSRtest/src/server/zNodeStream.js‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Transform } from "stream";
2-
import { create } from "domain";
3-
import { lstat } from "fs";
2+
// import { create } from "domain";
3+
// import { lstat } from "fs";
4+
import { renderToNodeStream, renderToStaticNodeStream } from "../../ModifiedReact.js";
45

56
const createCacheStream = (cache, streamingStart, memLife=0) => {
67
const bufferedChunks = [];
@@ -49,4 +50,27 @@ const createCacheStream = (cache, streamingStart, memLife=0) => {
4950
});
5051
};
5152

52-
export default createCacheStream;
53+
function zNodeStream(compo, staticMarkup, cache, res){
54+
55+
const htmlStart =
56+
'<html><head><title>Page</title></head><body><div id="react-root">';
57+
58+
const htmlEnd = "</div></body></html>";
59+
60+
const streamingStart = {
61+
sliceStartCount: htmlStart.length,
62+
}
63+
64+
const cacheStream = createCacheStream(cache, streamingStart);
65+
cacheStream.pipe(res);
66+
cacheStream.write(htmlStart);
67+
68+
const stream = staticMarkup? renderToStaticNodeStream(compo, cache, streamingStart) : renderToNodeStream(compo, cache, streamingStart);
69+
stream.pipe(cacheStream, { end: false });
70+
stream.on("end", () => {
71+
cacheStream.end(htmlEnd);
72+
});
73+
74+
}
75+
76+
export default zNodeStream;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /