Skip to content

Commit

Permalink
Expected behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed May 12, 2022
1 parent 8197c73 commit 412dab4
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/react-reconciler/src/__tests__/ReactNewContext-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,48 @@ describe('ReactNewContext', () => {
}
});

it('warns not if multiple renderers finished rendering the same context', () => {
spyOnDev(console, 'error');
const Context = React.createContext(0);

function Foo(props) {
Scheduler.unstable_yieldValue('Foo');
return null;
}

function App(props) {
return (
<Context.Provider value={props.value}>
<Foo />
<Foo />
</Context.Provider>
);
}

if (gate(flags => flags.enableSyncDefaultUpdates)) {
React.startTransition(() => {
ReactNoop.render(<App value={1} />);
});
} else {
ReactNoop.render(<App value={1} />);
}
expect(Scheduler).toFlushAndYield(['Foo', 'Foo']);

// Get a new copy of ReactNoop
jest.resetModules();
React = require('react');
ReactNoop = require('react-noop-renderer');
Scheduler = require('scheduler');

// Render the provider again using a different renderer
ReactNoop.render(<App value={1} />);
expect(Scheduler).toFlushAndYield(['Foo', 'Foo']);

if (__DEV__) {
expect(console.error).not.toHaveBeenCalled();
}
});

it('provider bails out if children and value are unchanged (like sCU)', () => {
const Context = React.createContext(0);

Expand Down

0 comments on commit 412dab4

Please sign in to comment.