Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/react-noop-renderer/src/ReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,11 @@ var ReactNoop = {

unbatchedUpdates: NoopRenderer.unbatchedUpdates,

flushSync: NoopRenderer.flushSync,
flushSync(fn: () => mixed) {
yieldedValues = [];
NoopRenderer.flushSync(fn);
return yieldedValues;
},

// Logs the current state of the tree.
dumpTree(rootID: string = DEFAULT_ROOT_ID) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
if (
!isWorking &&
root === nextRoot &&
expirationTime <= nextRenderExpirationTime
expirationTime < nextRenderExpirationTime
) {
// Restart the root from the top.
if (nextUnitOfWork !== null) {
Expand Down
67 changes: 67 additions & 0 deletions packages/react-reconciler/src/__tests__/ReactIncremental-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ describe('ReactIncremental', () => {
ops = [];

// This will abort the previous work and restart
ReactNoop.flushSync(() => ReactNoop.render(null));
ReactNoop.render(<Foo text="baz" />);

// Flush part of the new work
Expand Down Expand Up @@ -221,6 +222,7 @@ describe('ReactIncremental', () => {
expect(ops).toEqual(['setState1']);

// This will abort the previous work and restart
ReactNoop.flushSync(() => ReactNoop.render(<Foo />));
inst.setState(
() => {
ops.push('setState2');
Expand Down Expand Up @@ -1877,6 +1879,8 @@ describe('ReactIncremental', () => {
);
ReactNoop.flush();
expect(ops).toEqual([
'ShowLocale {"locale":"sv"}',
'ShowBoth {"locale":"sv"}',
'Intl {}',
'ShowLocale {"locale":"en"}',
'Router {}',
Expand Down Expand Up @@ -2648,4 +2652,67 @@ describe('ReactIncremental', () => {
'count:1, name:not brian',
]);
});

it('does not interrupt for update at same priority', () => {
function Parent(props) {
ReactNoop.yield('Parent: ' + props.step);
return <Child step={props.step} />;
}

function Child(props) {
ReactNoop.yield('Child: ' + props.step);
return null;
}

ReactNoop.render(<Parent step={1} />);
ReactNoop.flushThrough(['Parent: 1']);

// Interrupt at same priority
ReactNoop.render(<Parent step={2} />);

expect(ReactNoop.flush()).toEqual(['Child: 1', 'Parent: 2', 'Child: 2']);
});

it('does not interrupt for update at lower priority', () => {
function Parent(props) {
ReactNoop.yield('Parent: ' + props.step);
return <Child step={props.step} />;
}

function Child(props) {
ReactNoop.yield('Child: ' + props.step);
return null;
}

ReactNoop.render(<Parent step={1} />);
ReactNoop.flushThrough(['Parent: 1']);

// Interrupt at lower priority
ReactNoop.expire(2000);
ReactNoop.render(<Parent step={2} />);

expect(ReactNoop.flush()).toEqual(['Child: 1', 'Parent: 2', 'Child: 2']);
});

it('does interrupt for update at higher priority', () => {
function Parent(props) {
ReactNoop.yield('Parent: ' + props.step);
return <Child step={props.step} />;
}

function Child(props) {
ReactNoop.yield('Child: ' + props.step);
return null;
}

ReactNoop.render(<Parent step={1} />);
ReactNoop.flushThrough(['Parent: 1']);

// Interrupt at higher priority
expect(
ReactNoop.flushSync(() => ReactNoop.render(<Parent step={2} />)),
).toEqual(['Parent: 2', 'Child: 2']);

expect(ReactNoop.flush()).toEqual([]);
});
});