Skip to content

Commit

Permalink
Don't store stack state for Suspense element with no fallback [perf]
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Feb 20, 2019
1 parent 442be55 commit a9e19e8
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,11 @@ class PartialRenderer extends ReactDOMServerRenderer {
let node;
const {fallback} = element.props;
if (fallback !== undefined) {
node = this.createChild(TYPE_SUSPENSE, frame);
node = this.createChildWithStackState(TYPE_SUSPENSE, frame);
node.fallback = fallback;
this.suspenseNode = node;
} else {
node = this.createChild(null, frame);
node = this.createChild(null);
}

this.node = node;
Expand All @@ -324,7 +324,7 @@ class PartialRenderer extends ReactDOMServerRenderer {
const frame = this.stackPopOriginal.call(stack);

// Add node to tree
const node = this.createChild(TYPE_PROMISE, frame);
const node = this.createChildWithStackState(TYPE_PROMISE, frame);
node.element = element;
node.promise = promise;
node.resolved = false;
Expand Down Expand Up @@ -483,7 +483,9 @@ class PartialRenderer extends ReactDOMServerRenderer {
if (isRenderableElement(fallback)) suspenseFrame.children.push(fallback);
}

createChild(type, frame) {
createChildWithStackState(type, frame) {
const child = this.createChild(type);

// Get current contexts from new Context API
const {threadID} = this;
const contexts = [];
Expand All @@ -494,20 +496,26 @@ class PartialRenderer extends ReactDOMServerRenderer {
contexts.push(ctx);
}

// Record stackState
child.stackState = {
context: frame.context, // Contexts from legacy Context API
contexts, // Contexts from new Context API
domNamespace: frame.domNamespace,
currentSelectValue: this.currentSelectValue,
isRootElement: this.isRootElement && this.stack.length === this.nonDomFrames + 1
};

return child;
}

createChild(type) {
const parent = this.node;

const child = {
type,
parent,
parentSuspense: this.suspenseNode,
children: [],
stackState: {
context: frame.context, // Contexts from legacy Context API
contexts, // Contexts from new Context API
domNamespace: frame.domNamespace,
currentSelectValue: this.currentSelectValue,
isRootElement: this.isRootElement && this.stack.length === this.nonDomFrames + 1
}
children: []
};

parent.children.push(child);
Expand Down

0 comments on commit a9e19e8

Please sign in to comment.