Skip to content

Commit

Permalink
Revert "Cleanup enableSyncDefaultUpdate flag (facebook#26236)" (faceb…
Browse files Browse the repository at this point in the history
…ook#26528)

This reverts commit b2ae9dd.

While the feature flag is fully rolled out, these tests are also testing
behavior set with an unstable flag on root, which for now we want to
preserve.

Not sure if there's a better way then adding a dynamic feature flag to
the www build?
  • Loading branch information
kassens authored and AndyPengc12 committed Apr 15, 2024
1 parent dce8e3b commit e1df5a8
Show file tree
Hide file tree
Showing 36 changed files with 1,477 additions and 314 deletions.
58 changes: 58 additions & 0 deletions packages/react-art/src/__tests__/ReactART-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ 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;
let Surface;
let TestComponent;

let waitFor;

const Missing = {};

function testDOMNodeStructure(domNode, expectedStructure) {
Expand Down Expand Up @@ -76,6 +80,8 @@ describe('ReactART', () => {
Shape = ReactART.Shape;
Surface = ReactART.Surface;

({waitFor} = require('internal-test-utils'));

TestComponent = class extends React.Component {
group = React.createRef();

Expand Down Expand Up @@ -357,6 +363,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.log(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 = [];
await waitFor(['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 @@ -1984,9 +1984,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
Loading

0 comments on commit e1df5a8

Please sign in to comment.