Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce nodeArrival calls by taking in range of node indices #288

Merged
merged 2 commits into from
Jun 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/react-server/core/ClientController.js
Original file line number Diff line number Diff line change
Expand Up @@ -826,17 +826,19 @@ class ClientController extends EventEmitter {
ReactServerAgent.cache().lateArrival(url, dehydratedEntry);
}

nodeArrival (index) {
nodeArrival (startIndex, endIndex) {

// The server has just let us know that a pre-rendered root
// element has arrived. We'll grab a reference to its DOM
// node and un-block client-side rendering of the element that
// we're going to mount into it.
this._ensureRootNodeDfd(index).resolve(
this.mountNode.querySelector(
`div[${REACT_SERVER_DATA_ATTRIBUTE}="${index}"]`
)
);
for (var i = startIndex; i <= endIndex; i++) {
this._ensureRootNodeDfd(i).resolve(
this.mountNode.querySelector(
`div[${REACT_SERVER_DATA_ATTRIBUTE}="${i}"]`
)
);
}
}

failArrival () {
Expand Down
13 changes: 7 additions & 6 deletions packages/react-server/core/renderMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ function writeElements(res, elements) {

// We've already bootstrapped, so we can immediately tell the
// client controller to wake the new element we just sent.
wakeElement(res, i);
wakeElementRange(res, i, i);
} else if (i === elements.length - 1) {

// Page didn't emit `<TheFold/>`. Now we're done.
Expand Down Expand Up @@ -915,15 +915,16 @@ function bootstrapClient(res, lastElementSent) {
// function to avoid letting responses slip in between.
setupLateArrivals(res);

for (var i = 0; i <= lastElementSent; i++) {
wakeElement(res, i);
}
wakeElementRange(res, 0, lastElementSent);

RLS().haveBootstrapped = true;
}

function wakeElement(res, i) {
renderScriptsAsync([{ text: `__reactServerClientController.nodeArrival(${i})` }], res)
function wakeElementRange(res, startIndex, endIndex) {
endIndex = endIndex || startIndex;
renderScriptsAsync([{
text: `__reactServerClientController.nodeArrival(${startIndex},${endIndex})`,
}], res);
}

function setupLateArrivals(res) {
Expand Down