Skip to content

Commit f3dbc57

Browse files
authored
Merge pull request #34 from adifiore/master
update master
2 parents b4aaf13 + af13d79 commit f3dbc57

File tree

8 files changed

+2711
-95
lines changed

8 files changed

+2711
-95
lines changed

SSRtest/LRUCache.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

SSRtest/developmentBuild.js

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,18 +2750,28 @@ function createCacheStream(cache, streamingStart) {
27502750
var tagEnd = void 0;
27512751

27522752
do {
2753-
if (!tagStart) tagStart = streamingStart[component];else tagStart = html[tagEnd] === '<' ? tagEnd : html.indexOf('<', tagEnd);
2753+
if (!tagStart) {
2754+
tagStart = streamingStart[component];
2755+
} else {
2756+
tagStart = html[tagEnd] === '<' ? tagEnd : html.indexOf('<', tagEnd);
2757+
}
27542758
tagEnd = html.indexOf('>', tagStart) + 1;
27552759
// Skip stack logic for void/self-closing elements and HTML comments
27562760
if (html[tagEnd - 2] !== '/' && html[tagStart + 1] !== '!') {
27572761
// Push opening tags onto stack; pop closing tags off of stack
2758-
if (html[tagStart + 1] !== '/') tagStack.push(html.slice(tagStart, tagEnd));else tagStack.pop();
2762+
if (html[tagStart + 1] !== '/') {
2763+
tagStack.push(html.slice(tagStart, tagEnd));
2764+
} else {
2765+
tagStack.pop();
2766+
}
27592767
}
27602768
} while (tagStack.length !== 0);
27612769
// cache component by slicing 'html'
27622770
if (memLife) {
27632771
cache.set(component, html.slice(streamingStart[component], tagEnd), memLife, function (err) {
2764-
if (err) console.log(err);
2772+
if (err) {
2773+
console.log(err);
2774+
}
27652775
});
27662776
} else {
27672777
cache.set(component, html.slice(streamingStart[component], tagEnd));
@@ -2782,7 +2792,7 @@ function originalRenderToNodeStream(element, cache, streamingStart) {
27822792
return new ReactMarkupReadableStream(element, false, cache, streamingStart, memLife);
27832793
}
27842794

2785-
function renderToNodeStream(compo, cache, res) {
2795+
function renderToNodeStream(element, cache, res) {
27862796

27872797
var htmlStart = '<html><head><title>Page</title></head><body><div id="react-root">';
27882798

@@ -2796,7 +2806,7 @@ function renderToNodeStream(compo, cache, res) {
27962806
cacheStream.pipe(res);
27972807
cacheStream.write(htmlStart);
27982808

2799-
var stream$$1 = originalRenderToNodeStream(compo, cache, streamingStart);
2809+
var stream$$1 = originalRenderToNodeStream(element, cache, streamingStart);
28002810
stream$$1.pipe(cacheStream, { end: false });
28012811
stream$$1.on("end", function () {
28022812
cacheStream.end(htmlEnd);
@@ -2808,12 +2818,32 @@ function renderToNodeStream(compo, cache, res) {
28082818
* such as data-react-id that React uses internally.
28092819
* See https://reactjs.org/docs/react-dom-stream.html#rendertostaticnodestream
28102820
*/
2811-
function renderToStaticNodeStream(element, cache, streamingStart) {
2821+
function originalRenderToStaticNodeStream(element, cache, streamingStart) {
28122822
var memLife = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
28132823

28142824
return new ReactMarkupReadableStream(element, true, cache, streamingStart, memLife);
28152825
}
28162826

2827+
function renderToStaticNodeStream(element, cache, res) {
2828+
var htmlStart = '<html><head><title>Page</title></head><body><div id="react-root">';
2829+
2830+
var htmlEnd = '</div></body></html>';
2831+
2832+
var streamingStart = {
2833+
sliceStartCount: htmlStart.length
2834+
};
2835+
2836+
var cacheStream = createCacheStream(cache, streamingStart);
2837+
cacheStream.pipe(res);
2838+
cacheStream.write(htmlStart);
2839+
2840+
var stream$$1 = originalRenderToStaticNodeStream(element, cache, streamingStart);
2841+
stream$$1.pipe(cacheStream, { end: false });
2842+
stream$$1.on("end", function () {
2843+
cacheStream.end(htmlEnd);
2844+
});
2845+
}
2846+
28172847
function createCommonjsModule(fn, module) {
28182848
return module = { exports: {} }, fn(module, module.exports), module.exports;
28192849
}

SSRtest/productionBuild.js

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,18 +1646,28 @@ function createCacheStream(cache, streamingStart) {
16461646
var tagEnd = void 0;
16471647

16481648
do {
1649-
if (!tagStart) tagStart = streamingStart[component];else tagStart = html[tagEnd] === '<' ? tagEnd : html.indexOf('<', tagEnd);
1649+
if (!tagStart) {
1650+
tagStart = streamingStart[component];
1651+
} else {
1652+
tagStart = html[tagEnd] === '<' ? tagEnd : html.indexOf('<', tagEnd);
1653+
}
16501654
tagEnd = html.indexOf('>', tagStart) + 1;
16511655
// Skip stack logic for void/self-closing elements and HTML comments
16521656
if (html[tagEnd - 2] !== '/' && html[tagStart + 1] !== '!') {
16531657
// Push opening tags onto stack; pop closing tags off of stack
1654-
if (html[tagStart + 1] !== '/') tagStack.push(html.slice(tagStart, tagEnd));else tagStack.pop();
1658+
if (html[tagStart + 1] !== '/') {
1659+
tagStack.push(html.slice(tagStart, tagEnd));
1660+
} else {
1661+
tagStack.pop();
1662+
}
16551663
}
16561664
} while (tagStack.length !== 0);
16571665
// cache component by slicing 'html'
16581666
if (memLife) {
16591667
cache.set(component, html.slice(streamingStart[component], tagEnd), memLife, function (err) {
1660-
if (err) console.log(err);
1668+
if (err) {
1669+
console.log(err);
1670+
}
16611671
});
16621672
} else {
16631673
cache.set(component, html.slice(streamingStart[component], tagEnd));
@@ -1678,7 +1688,7 @@ function originalRenderToNodeStream(element, cache, streamingStart) {
16781688
return new ReactMarkupReadableStream(element, false, cache, streamingStart, memLife);
16791689
}
16801690

1681-
function renderToNodeStream(compo, cache, res) {
1691+
function renderToNodeStream(element, cache, res) {
16821692

16831693
var htmlStart = '<html><head><title>Page</title></head><body><div id="react-root">';
16841694

@@ -1692,7 +1702,7 @@ function renderToNodeStream(compo, cache, res) {
16921702
cacheStream.pipe(res);
16931703
cacheStream.write(htmlStart);
16941704

1695-
var stream$$1 = originalRenderToNodeStream(compo, cache, streamingStart);
1705+
var stream$$1 = originalRenderToNodeStream(element, cache, streamingStart);
16961706
stream$$1.pipe(cacheStream, { end: false });
16971707
stream$$1.on("end", function () {
16981708
cacheStream.end(htmlEnd);
@@ -1704,12 +1714,32 @@ function renderToNodeStream(compo, cache, res) {
17041714
* such as data-react-id that React uses internally.
17051715
* See https://reactjs.org/docs/react-dom-stream.html#rendertostaticnodestream
17061716
*/
1707-
function renderToStaticNodeStream(element, cache, streamingStart) {
1717+
function originalRenderToStaticNodeStream(element, cache, streamingStart) {
17081718
var memLife = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
17091719

17101720
return new ReactMarkupReadableStream(element, true, cache, streamingStart, memLife);
17111721
}
17121722

1723+
function renderToStaticNodeStream(element, cache, res) {
1724+
var htmlStart = '<html><head><title>Page</title></head><body><div id="react-root">';
1725+
1726+
var htmlEnd = '</div></body></html>';
1727+
1728+
var streamingStart = {
1729+
sliceStartCount: htmlStart.length
1730+
};
1731+
1732+
var cacheStream = createCacheStream(cache, streamingStart);
1733+
cacheStream.pipe(res);
1734+
cacheStream.write(htmlStart);
1735+
1736+
var stream$$1 = originalRenderToStaticNodeStream(element, cache, streamingStart);
1737+
stream$$1.pipe(cacheStream, { end: false });
1738+
stream$$1.on("end", function () {
1739+
cacheStream.end(htmlEnd);
1740+
});
1741+
}
1742+
17131743
function createCommonjsModule(fn, module) {
17141744
return module = { exports: {} }, fn(module, module.exports), module.exports;
17151745
}

SSRtest/src/server/index.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ export default ({ clientStats }) => async (req, res) => {
4040
// cacheStream.pipe(res);
4141
// cacheStream.write(htmlStart);
4242

43-
// const stream = ReactCC.renderToNodeStream(<App />, cache, streamingStart);
44-
// stream.pipe(cacheStream, { end: false });
45-
// stream.on("end", () => {
46-
// cacheStream.end(htmlEnd);
47-
// });
48-
4943
}
5044
else if (false){
5145
const app = <App />;
@@ -67,6 +61,6 @@ export default ({ clientStats }) => async (req, res) => {
6761
styles,
6862
cssHash
6963
});
70-
// }
64+
}
7165

72-
};
66+
};

SSRtest/src/shared/App.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ export default class App extends Component {
1818
<div>
1919
<h1>THIS IS AN APP</h1>
2020
<Button />
21-
<BlogPost />
22-
<BlogPost />
23-
21+
<BlogPost />
22+
<BlogPost />
2423
<List />
2524

2625
</div>

0 commit comments

Comments
 (0)