Skip to content

Commit

Permalink
Revert "Cleanup enableSyncDefaultUpdate flag (facebook#26236)"
Browse files Browse the repository at this point in the history
This reverts commit b2ae9dd.
  • Loading branch information
kassens committed Mar 31, 2023
1 parent ca01f35 commit 81a639f
Show file tree
Hide file tree
Showing 35 changed files with 1,397 additions and 301 deletions.
54 changes: 54 additions & 0 deletions packages/react-art/src/__tests__/ReactART-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const ReactTestRenderer = require('react-test-renderer');

// Isolate the noop renderer
jest.resetModules();
const ReactNoop = require('react-noop-renderer');
const Scheduler = require('scheduler');

let Group;
let Shape;
Expand Down Expand Up @@ -357,6 +359,58 @@ describe('ReactART', () => {
doClick(instance);
expect(onClick2).toBeCalled();
});

// @gate !enableSyncDefaultUpdates
it('can concurrently render with a "primary" renderer while sharing context', async () => {
const CurrentRendererContext = React.createContext(null);

function Yield(props) {
Scheduler.unstable_yieldValue(props.value);
return null;
}

let ops = [];
function LogCurrentRenderer() {
return (
<CurrentRendererContext.Consumer>
{currentRenderer => {
ops.push(currentRenderer);
return null;
}}
</CurrentRendererContext.Consumer>
);
}

// Using test renderer instead of the DOM renderer here because async
// testing APIs for the DOM renderer don't exist.
ReactNoop.render(
<CurrentRendererContext.Provider value="Test">
<Yield value="A" />
<Yield value="B" />
<LogCurrentRenderer />
<Yield value="C" />
</CurrentRendererContext.Provider>,
);

await waitFor(['A']);

ReactDOM.render(
<Surface>
<LogCurrentRenderer />
<CurrentRendererContext.Provider value="ART">
<LogCurrentRenderer />
</CurrentRendererContext.Provider>
</Surface>,
container,
);

expect(ops).toEqual([null, 'ART']);

ops = [];
expect(Scheduler).toFlushAndYield(['B', 'C']);

expect(ops).toEqual(['Test']);
});
});

describe('ReactARTComponents', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,11 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
expect(container.textContent).toEqual('not hovered');

await waitFor(['hovered']);
expect(container.textContent).toEqual('hovered');
if (gate(flags => flags.enableSyncDefaultUpdates)) {
expect(container.textContent).toEqual('hovered');
} else {
expect(container.textContent).toEqual('not hovered');
}
});
expect(container.textContent).toEqual('hovered');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2036,7 +2036,14 @@ describe('ReactDOMServerPartialHydration', () => {
suspend = true;

await act(async () => {
await waitFor(['Before', 'After']);
if (gate(flags => flags.enableSyncDefaultUpdates)) {
await waitFor(['Before', 'After']);
} else {
await waitFor(['Before']);
// This took a long time to render.
Scheduler.unstable_advanceTime(1000);
await waitFor(['After']);
}

// This will cause us to skip the second row completely.
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1995,9 +1995,13 @@ describe('DOMPluginEventSystem', () => {
log.length = 0;

// Increase counter
React.startTransition(() => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
root.render(<Test counter={1} />);
});
} else {
root.render(<Test counter={1} />);
});
}
// Yield before committing
await waitFor(['Test']);

Expand Down
7 changes: 5 additions & 2 deletions packages/react-reconciler/src/ReactFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
enableProfilerTimer,
enableScopeAPI,
enableLegacyHidden,
enableSyncDefaultUpdates,
allowConcurrentByDefault,
enableTransitionTracing,
enableDebugTracing,
Expand Down Expand Up @@ -458,9 +459,11 @@ export function createHostRootFiber(
mode |= StrictLegacyMode | StrictEffectsMode;
}
if (
// We only use this flag for our repo tests to check both behaviors.
// TODO: Flip this flag and rename it something like "forceConcurrentByDefaultForTesting"
!enableSyncDefaultUpdates ||
// Only for internal experiments.
allowConcurrentByDefault &&
concurrentUpdatesByDefaultOverride
(allowConcurrentByDefault && concurrentUpdatesByDefaultOverride)
) {
mode |= ConcurrentUpdatesByDefaultMode;
}
Expand Down
102 changes: 75 additions & 27 deletions packages/react-reconciler/src/__tests__/ReactExpiration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ describe('ReactExpiration', () => {

it('increases priority of updates as time progresses', async () => {
ReactNoop.render(<Text text="Step 1" />);
React.startTransition(() => {
ReactNoop.render(<Text text="Step 2" />);
});
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
ReactNoop.render(<Text text="Step 2" />);
});
} else {
ReactNoop.render(<span prop="done" />);
}

await waitFor(['Step 1']);

Expand Down Expand Up @@ -162,9 +166,13 @@ describe('ReactExpiration', () => {

// First, show what happens for updates in two separate events.
// Schedule an update.
React.startTransition(() => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
ReactNoop.render(<TextClass text="A" />);
});
} else {
ReactNoop.render(<TextClass text="A" />);
});
}
// Advance the timer.
Scheduler.unstable_advanceTime(2000);
// Partially flush the first update, then interrupt it.
Expand Down Expand Up @@ -219,9 +227,13 @@ describe('ReactExpiration', () => {

// First, show what happens for updates in two separate events.
// Schedule an update.
React.startTransition(() => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
ReactNoop.render(<TextClass text="A" />);
});
} else {
ReactNoop.render(<TextClass text="A" />);
});
}
// Advance the timer.
Scheduler.unstable_advanceTime(2000);
// Partially flush the first update, then interrupt it.
Expand Down Expand Up @@ -287,9 +299,13 @@ describe('ReactExpiration', () => {
}

// Initial mount
React.startTransition(() => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
ReactNoop.render(<App />);
});
} else {
ReactNoop.render(<App />);
});
}
await waitForAll([
'initial [A] [render]',
'initial [B] [render]',
Expand All @@ -302,9 +318,13 @@ describe('ReactExpiration', () => {
]);

// Partial update
React.startTransition(() => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
subscribers.forEach(s => s.setState({text: '1'}));
});
} else {
subscribers.forEach(s => s.setState({text: '1'}));
});
}
await waitFor(['1 [A] [render]', '1 [B] [render]']);

// Before the update can finish, update again. Even though no time has
Expand All @@ -330,9 +350,13 @@ describe('ReactExpiration', () => {
);
}

React.startTransition(() => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
root.render(<App />);
});
} else {
root.render(<App />);
});
}

await waitFor(['A']);
await waitFor(['B']);
Expand All @@ -359,9 +383,13 @@ describe('ReactExpiration', () => {
</>
);
}
React.startTransition(() => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
root.render(<App />);
});
} else {
root.render(<App />);
});
}

await waitFor(['A']);
await waitFor(['B']);
Expand Down Expand Up @@ -395,10 +423,14 @@ describe('ReactExpiration', () => {
React = require('react');

ReactNoop.render(<Text text="Step 1" />);
React.startTransition(() => {
ReactNoop.render(<Text text="Step 2" />);
});
await waitFor(['Step 1']);
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
ReactNoop.render(<Text text="Step 2" />);
});
await waitFor(['Step 1']);
} else {
ReactNoop.render('Hi');
}

// The update should not have expired yet.
await unstable_waitForExpired([]);
Expand All @@ -419,9 +451,13 @@ describe('ReactExpiration', () => {
// Before scheduling an update, advance the current time.
Scheduler.unstable_advanceTime(10000);

React.startTransition(() => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
ReactNoop.render('Hi');
});
} else {
ReactNoop.render('Hi');
});
}
await unstable_waitForExpired([]);
expect(ReactNoop).toMatchRenderedOutput(null);

Expand Down Expand Up @@ -462,9 +498,13 @@ describe('ReactExpiration', () => {

// First demonstrate what happens when there's no starvation
await act(async () => {
React.startTransition(() => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
updateNormalPri();
});
} else {
updateNormalPri();
});
}
await waitFor(['Sync pri: 0']);
updateSyncPri();
assertLog(['Sync pri: 1', 'Normal pri: 0']);
Expand All @@ -482,9 +522,13 @@ describe('ReactExpiration', () => {

// Do the same thing, but starve the first update
await act(async () => {
React.startTransition(() => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
updateNormalPri();
});
} else {
updateNormalPri();
});
}
await waitFor(['Sync pri: 1']);

// This time, a lot of time has elapsed since the normal pri update
Expand Down Expand Up @@ -645,9 +689,13 @@ describe('ReactExpiration', () => {
expect(root).toMatchRenderedOutput('A0BC');

await act(async () => {
React.startTransition(() => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
root.render(<App step={1} />);
});
} else {
root.render(<App step={1} />);
});
}
await waitForAll(['Suspend! [A1]', 'Loading...']);

// Lots of time elapses before the promise resolves
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ describe('ReactFlushSync', () => {

const root = ReactNoop.createRoot();
await act(async () => {
React.startTransition(() => {
if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
root.render(<App />);
});
} else {
root.render(<App />);
});
}
// This will yield right before the passive effect fires
await waitForPaint(['0, 0']);

Expand Down
Loading

0 comments on commit 81a639f

Please sign in to comment.