Check if we're in sync mode before deprioritizing hidden subtrees
Andrew Clark committed
Feb 27, 2017 at 15:55 UTC
4ef197b7d405b00a07190aa014435fae283744bb
3 files changed
+12
-8
scripts/fiber/tests-passing.txt
+1
@@ -854,6 +854,7 @@ src/renderers/__tests__/ReactUpdates-test.js
854
* handles reentrant mounting in synchronous mode
855
* mounts and unmounts are sync even in a batch
856
* does not re-render if state update is null
857
+* synchronously renders hidden subtrees
858
859
src/renderers/__tests__/refs-destruction-test.js
860
* should remove refs when destroying the parent
src/renderers/__tests__/ReactUpdates-test.js
+6
-5
@@ -1160,15 +1160,16 @@ describe('ReactUpdates', () => {
1160
expect(mounts).toBe(1);
1161
});
1162
1163
- it('mounts and unmounts are sync even in a batch', done => {
1163
+ it('mounts and unmounts are sync even in a batch', () => {
1164
+ var ops = [];
1165
var container = document.createElement('div');
1166
ReactDOM.unstable_batchedUpdates(() => {
1167
ReactDOM.render(<div>Hello</div>, container);
1167
- expect(container.textContent).toEqual('Hello');
1168
+ ops.push(container.textContent);
1169
ReactDOM.unmountComponentAtNode(container);
1169
- expect(container.textContent).toEqual('');
1170
- done();
1170
+ ops.push(container.textContent);
1171
});
1172
+ expect(ops).toEqual(['Hello', '']);
1173
});
1174
1175
it('does not re-render if state update is null', () => {
@@ -1192,7 +1193,7 @@ describe('ReactUpdates', () => {
1193
1194
// Will change once we switch to async by default
1195
it('synchronously renders hidden subtrees', () => {
1195
- let container = document.createElement('div');
1196
+ const container = document.createElement('div');
1197
let ops = [];
1198
1199
function Baz() {
src/renderers/shared/fiber/ReactFiberBeginWork.js
+5
-3
@@ -77,7 +77,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
77
getPriorityContext : () => PriorityLevel,
78
) {
79
80
- const { shouldSetTextContent } = config;
80
+ const { shouldSetTextContent, useSyncScheduling } = config;
81
82
const {
83
pushHostContext,
@@ -357,7 +357,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
357
);
358
}
359
} else if (nextProps === null || memoizedProps === nextProps) {
360
- if (memoizedProps.hidden &&
360
+ if (!useSyncScheduling &&
361
+ memoizedProps.hidden &&
362
workInProgress.pendingWorkPriority !== OffscreenPriority) {
363
// This subtree still has work, but it should be deprioritized so we need
364
// to bail out and not do any work yet.
@@ -398,7 +399,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
399
400
markRef(current, workInProgress);
401
401
- if (nextProps.hidden &&
402
+ if (!useSyncScheduling &&
403
+ nextProps.hidden &&
404
workInProgress.pendingWorkPriority !== OffscreenPriority) {
405
// If this host component is hidden, we can bail out on the children.
406
// We'll rerender the children later at the lower priority.