Skip to content

Commit

Permalink
Fix context memory leak (#10680)
Browse files Browse the repository at this point in the history
* Fix context memory leak

* Fix Flow
  • Loading branch information
gaearon authored Sep 12, 2017
1 parent 43dae74 commit 65b9ad9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/renderers/shared/fiber/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
return workInProgress.child;
}

function updateHostRoot(current, workInProgress, priorityLevel) {
function pushHostRootContext(workInProgress) {
const root = (workInProgress.stateNode: FiberRoot);
if (root.pendingContext) {
pushTopLevelContextObject(
Expand All @@ -317,9 +317,11 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
// Should always be set
pushTopLevelContextObject(workInProgress, root.context, false);
}

pushHostContainer(workInProgress, root.containerInfo);
}

function updateHostRoot(current, workInProgress, priorityLevel) {
pushHostRootContext(workInProgress);
const updateQueue = workInProgress.updateQueue;
if (updateQueue !== null) {
const prevState = workInProgress.memoizedState;
Expand Down Expand Up @@ -777,8 +779,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
pushContextProvider(workInProgress);
break;
case HostRoot:
const root: FiberRoot = workInProgress.stateNode;
pushHostContainer(workInProgress, root.containerInfo);
pushHostRootContext(workInProgress);
break;
default:
invariant(
Expand Down
8 changes: 6 additions & 2 deletions src/renderers/shared/fiber/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import type {FiberRoot} from 'ReactFiberRoot';
import type {HostConfig} from 'ReactFiberReconciler';

var {reconcileChildFibers} = require('ReactChildFiber');
var {popContextProvider} = require('ReactFiberContext');
var {
popContextProvider,
popTopLevelContextObject,
} = require('ReactFiberContext');
var ReactTypeOfWork = require('ReactTypeOfWork');
var ReactTypeOfSideEffect = require('ReactTypeOfSideEffect');
var ReactPriorityLevel = require('ReactPriorityLevel');
Expand Down Expand Up @@ -211,7 +214,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
return null;
}
case HostRoot: {
// TODO: Pop the host container after #8607 lands.
popHostContainer(workInProgress);
popTopLevelContextObject(workInProgress);
const fiberRoot = (workInProgress.stateNode: FiberRoot);
if (fiberRoot.pendingContext) {
fiberRoot.context = fiberRoot.pendingContext;
Expand Down
5 changes: 5 additions & 0 deletions src/renderers/shared/fiber/ReactFiberContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ function popContextProvider(fiber: Fiber): void {
}
exports.popContextProvider = popContextProvider;

exports.popTopLevelContextObject = function(fiber: Fiber) {
pop(didPerformWorkStackCursor, fiber);
pop(contextStackCursor, fiber);
};

exports.pushTopLevelContextObject = function(
fiber: Fiber,
context: Object,
Expand Down

0 comments on commit 65b9ad9

Please sign in to comment.