You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Comment out useContext(MyContext) in Component and repeat. It will be much faster.
Expected behavior
It should be faster.
Root cause
Subscribing to a context provider overrides componentWillUnmount:
this.sub = function (c) {
subs.push(c);
var old = c.componentWillUnmount;
c.componentWillUnmount = function () {
subs.splice(subs.indexOf(c), 1);
if (old) { old.call(c); }
};
};
When unmounting the entire tree, repeatedly splicing the subs array is slow because it shifts the array. If the provider itself is unmounting, it could instead immediately remove all its subs. Alternatively if changing the render order of subscribed components isn't a breaking change, it could avoid the splice cost like this:
this.sub = function (c) {
subs.push(c);
var old = c.componentWillUnmount;
c.componentWillUnmount = function () {
var index = subs.indexOf(c);
var last = subs.pop();
if (last !== c){
subs[index] = last;
}
if (old) { old.call(c); }
};
};
The text was updated successfully, but these errors were encountered:
Describe the bug
Unmounting a context provider is slow if there are many components subscribed to its context.
To Reproduce
Steps to reproduce the behavior:
useContext(MyContext)
in Component and repeat. It will be much faster.Expected behavior
It should be faster.
Root cause
Subscribing to a context provider overrides componentWillUnmount:
When unmounting the entire tree, repeatedly splicing the subs array is slow because it shifts the array. If the provider itself is unmounting, it could instead immediately remove all its subs. Alternatively if changing the render order of subscribed components isn't a breaking change, it could avoid the splice cost like this:
The text was updated successfully, but these errors were encountered: