Repository: facebook/react
File: packages/react-reconciler/src/__tests__/ReactNewContext-test.js (JavaScript)

Code before:
        });
      } else {
        ReactNoop.render(<App value={1} />);
      }
      // Render past the Provider, but don't commit yet
      expect(Scheduler).toFlushAndYieldThrough(['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.calls.argsFor(0)[0]).toContain(
          'Detected multiple renderers concurrently rendering the same ' +
            'context provider. This is currently unsupported',
        );
      }
    });

    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']);

Review comment (suggestion):
```suggestion
    it('does not warn if multiple renderers use the same context sequentially', () => {
```

Code after:
        });
      } else {
        ReactNoop.render(<App value={1} />);
      }
      // Render past the Provider, but don't commit yet
      expect(Scheduler).toFlushAndYieldThrough(['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.calls.argsFor(0)[0]).toContain(
          'Detected multiple renderers concurrently rendering the same ' +
            'context provider. This is currently unsupported',
        );
      }
    });

    it('does not warn if multiple renderers use the same context sequentially', () => {
      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']);