Skip to content

Commit

Permalink
Don't store suspended state on renderer [refactor]
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Mar 17, 2019
1 parent 6ea0420 commit 3f3654a
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ class PartialRenderer extends ReactDOMServerRenderer {
};
this.tree = tree;
this.node = tree;

// Init suspense state
this.suspenseNode = null;
this.suspended = false;

// Init lazy node awaiting counter
this.numAwaiting = 0;
Expand Down Expand Up @@ -90,7 +87,10 @@ class PartialRenderer extends ReactDOMServerRenderer {
this.errored(err);
}

if (this.numAwaiting !== 0 || this.suspended) return;
if (this.numAwaiting !== 0) return;

const {suspenseNode} = this;
if (suspenseNode && suspenseNode.suspended) return;

// Finished processing
this.destroy();
Expand Down Expand Up @@ -272,7 +272,6 @@ class PartialRenderer extends ReactDOMServerRenderer {
node.fallback = fallback;
node.suspended = false;
this.suspenseNode = node;
this.suspended = false;

this.node = node;

Expand All @@ -284,7 +283,8 @@ class PartialRenderer extends ReactDOMServerRenderer {

handlePromise(element, promise) {
// If no enclosing suspense boundary, abort promise and exit with error
if (!this.suspenseNode) {
const {suspenseNode} = this;
if (!suspenseNode) {
followAndAbort(promise);
this.halt(new Error(
'A React component suspended while rendering, but no fallback UI was specified.\n\n' +
Expand All @@ -302,7 +302,7 @@ class PartialRenderer extends ReactDOMServerRenderer {
// TODO Check this works if promise resolves sync.
// I think it won't because on client side it will render immediately
// and that could include more lazy elements.
if (this.suspended) {
if (suspenseNode.suspended) {
followAndAbort(promise);
return;
}
Expand Down Expand Up @@ -376,7 +376,6 @@ class PartialRenderer extends ReactDOMServerRenderer {
this.node = node;
const suspenseNode = node.parentSuspense;
this.suspenseNode = suspenseNode;
this.suspended = suspenseNode ? suspenseNode.suspended : false;
this.restoreStack(node.stackState, element);

// Render element
Expand All @@ -389,7 +388,7 @@ class PartialRenderer extends ReactDOMServerRenderer {
this.resetProviders();

// If suspended, render fallback of suspense boundary
if (!this.suspended) return;
if (!suspenseNode || !suspenseNode.suspended) return;

// Convert node to fallback and discard children
const {fallback} = suspenseNode;
Expand Down Expand Up @@ -451,7 +450,6 @@ class PartialRenderer extends ReactDOMServerRenderer {
this.abortDescendents(suspenseNode);

// Suspend
this.suspended = true;
suspenseNode.suspended = true;
}

Expand Down Expand Up @@ -527,15 +525,12 @@ class PartialRenderer extends ReactDOMServerRenderer {
}

popSuspense(node, frame) {
const {suspended} = this,
{fallback} = node;
const {fallback} = node;

// Step down suspense stack
const {parentSuspense} = node;
this.suspenseNode = parentSuspense;
this.suspended = parentSuspense ? parentSuspense.suspended : false;
this.suspenseNode = node.parentSuspense;

if (!suspended) return;
if (!node.suspended) return;

// Was suspended
// Convert node to fallback
Expand Down

0 comments on commit 3f3654a

Please sign in to comment.