Skip to content

Commit

Permalink
Remove clearProviders patch
Browse files Browse the repository at this point in the history
Closes #4.
  • Loading branch information
overlookmotel committed Feb 24, 2019
1 parent 86c62dc commit 40bea1e
Showing 1 changed file with 10 additions and 46 deletions.
56 changes: 10 additions & 46 deletions lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,41 +72,6 @@ class PartialRenderer extends ReactDOMServerRenderer {
this.stack[0].footer = '_';
}

/*
* `.destroy()` and `.clearProviders()` methods are added here to fix bug in
* ReactDOM 16.7.0-16.8.2.
* See https://github.com/facebook/react/issues/14705
* This bug will have worse effects with this extension of the class, as
* contexts are added to the context stack without adding to the frame
* stack, so leftover context values crossing over into other threads will
* be much more common.
* `.destroy()` prototype method is removed again at bottom of this script
* if `.clearProviders()` prototype method exists already on
* ReactDOMServerRenderer.
*
* TODO Alter this when updating to ReactDOM > 16.8.2 which includes
* commit fixing this lands in stable release.
* https://github.com/facebook/react/commit/ab7a67b1dc0e44bf74545ccf51a8c143b3af7402
*/
destroy() {
if (!this.exhausted) this.clearProviders();
super.destroy();
}

clearProviders() {
// Restore any remaining providers on the stack to previous values
for (let index = this.contextIndex; index >= 0; index--) {
const context = this.contextStack[index];
const previousValue = this.contextValueStack[index];
context[this.threadID] = previousValue;
}
}

resetProviders() {
this.clearProviders();
this.contextIndex = -1;
}

/*
* Read async
*/
Expand Down Expand Up @@ -641,6 +606,16 @@ class PartialRenderer extends ReactDOMServerRenderer {
}
}

/*
* Reset all Providers in stack.
* ReactDOM's native `.clearProviders()` method resets the content of all
* Providers, but does not reset `.contextIndex`.
*/
resetProviders() {
this.clearProviders();
this.contextIndex = -1;
}

/**
* Abort all descendents (children, children's children etc) of a node.
* If promise on lazy component has `.abort()` method, it is called.
Expand Down Expand Up @@ -684,15 +659,4 @@ function abort(promise) {
if (typeof promise.abort === 'function') promise.abort();
}

/*
* If ReactDOM is version which already has `.clearProviders()` method on
* `PartialRenderer` class, remove `.destroy()` and `.clearProviders()` methods
* overrides in this subclass.
* (see comments above on `.destroy()` method)
*/
if (ReactDOMServerRenderer.prototype.clearProviders) {
delete PartialRenderer.prototype.clearProviders;
delete PartialRenderer.prototype.destroy;
}

module.exports = PartialRenderer;

0 comments on commit 40bea1e

Please sign in to comment.