Check if we're in sync mode before deprioritizing hidden subtrees

This commit is contained in:
Andrew Clark
2017-02-27 15:55:30 -08:00
committed by Andrew Clark
parent 81eef12507
commit 4ef197b7d4
3 changed files with 12 additions and 8 deletions

View File

@@ -854,6 +854,7 @@ src/renderers/__tests__/ReactUpdates-test.js
* handles reentrant mounting in synchronous mode
* mounts and unmounts are sync even in a batch
* does not re-render if state update is null
* synchronously renders hidden subtrees
src/renderers/__tests__/refs-destruction-test.js
* should remove refs when destroying the parent

View File

@@ -1160,15 +1160,16 @@ describe('ReactUpdates', () => {
expect(mounts).toBe(1);
});
it('mounts and unmounts are sync even in a batch', done => {
it('mounts and unmounts are sync even in a batch', () => {
var ops = [];
var container = document.createElement('div');
ReactDOM.unstable_batchedUpdates(() => {
ReactDOM.render(<div>Hello</div>, container);
expect(container.textContent).toEqual('Hello');
ops.push(container.textContent);
ReactDOM.unmountComponentAtNode(container);
expect(container.textContent).toEqual('');
done();
ops.push(container.textContent);
});
expect(ops).toEqual(['Hello', '']);
});
it('does not re-render if state update is null', () => {
@@ -1192,7 +1193,7 @@ describe('ReactUpdates', () => {
// Will change once we switch to async by default
it('synchronously renders hidden subtrees', () => {
let container = document.createElement('div');
const container = document.createElement('div');
let ops = [];
function Baz() {

View File

@@ -77,7 +77,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
getPriorityContext : () => PriorityLevel,
) {
const { shouldSetTextContent } = config;
const { shouldSetTextContent, useSyncScheduling } = config;
const {
pushHostContext,
@@ -357,7 +357,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
);
}
} else if (nextProps === null || memoizedProps === nextProps) {
if (memoizedProps.hidden &&
if (!useSyncScheduling &&
memoizedProps.hidden &&
workInProgress.pendingWorkPriority !== OffscreenPriority) {
// This subtree still has work, but it should be deprioritized so we need
// to bail out and not do any work yet.
@@ -398,7 +399,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
markRef(current, workInProgress);
if (nextProps.hidden &&
if (!useSyncScheduling &&
nextProps.hidden &&
workInProgress.pendingWorkPriority !== OffscreenPriority) {
// If this host component is hidden, we can bail out on the children.
// We'll rerender the children later at the lower priority.