Bugfix: nextFlushedRoot should always be set when performing work (#11558)

Fixes an issue where performWorkOnRoot was called, but nextFlushedRoot
was not set. This happened in a special branch where we synchronously
flush newly mounted DOM trees outside the normal work loop.

Arguably, performWorkOnRoot should read from the globally assigned root
and expiration time instead of accepting arguments, since those
arguments are expected to be the same as the global values, anyway. I
decided against that since the global values could be null, so reading
from them would require extra null checks.
This commit is contained in:
Andrew Clark
2017-11-15 12:17:21 -08:00
committed by GitHub
parent 3322f6bf31
commit 77f576ce16
2 changed files with 15 additions and 1 deletions
@@ -2001,4 +2001,16 @@ describe('ReactErrorBoundaries', () => {
// Error should be the first thrown
expect(caughtError.message).toBe('child sad');
});
it('propagates uncaught error inside unbatched initial mount', () => {
function Foo() {
throw new Error('foo error');
}
const container = document.createElement('div');
expect(() => {
ReactDOM.unstable_batchedUpdates(() => {
ReactDOM.render(<Foo />, container);
});
}).toThrow('foo error');
});
});
+3 -1
View File
@@ -1330,7 +1330,9 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
if (isUnbatchingUpdates) {
// ...unless we're inside unbatchedUpdates, in which case we should
// flush it now.
performWorkOnRoot(root, Sync);
nextFlushedRoot = root;
nextFlushedExpirationTime = Sync;
performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime);
}
return;
}