@samitouri / QOS-React / commits / 77f576ce16

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.

Andrew Clark committed Nov 15, 2017 at 12:17 UTC 77f576ce16d02322eabc7a3e754f5c7fb44bc375
2 files changed +15 -1
packages/react-dom/src/__tests__/ReactErrorBoundaries-test.js
+12
@@ -2001,4 +2001,16 @@ describe('ReactErrorBoundaries', () => {
2001 // Error should be the first thrown
2002 expect(caughtError.message).toBe('child sad');
2003 });
2004 +
2005 + it('propagates uncaught error inside unbatched initial mount', () => {
2006 + function Foo() {
2007 + throw new Error('foo error');
2008 + }
2009 + const container = document.createElement('div');
2010 + expect(() => {
2011 + ReactDOM.unstable_batchedUpdates(() => {
2012 + ReactDOM.render(<Foo />, container);
2013 + });
2014 + }).toThrow('foo error');
2015 + });
2016 });
packages/react-reconciler/src/ReactFiberScheduler.js
+3 -1
@@ -1330,7 +1330,9 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
1330 if (isUnbatchingUpdates) {
1331 // ...unless we're inside unbatchedUpdates, in which case we should
1332 // flush it now.
1333 - performWorkOnRoot(root, Sync);
1333 + nextFlushedRoot = root;
1334 + nextFlushedExpirationTime = Sync;
1335 + performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime);
1336 }
1337 return;
1338 }