build: import useSyncExternalStore from react when using react 18 (#37212)

Fixes #37197 

tested with `examples/analyze-bundles/`, stripped off 300b of the the use-sync-external-store shim when applied the code change. 

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
This commit is contained in:
Jiachi Liu 2022-05-26 18:07:37 +02:00 committed by GitHub
parent 6a5bdb5d80
commit 4340b4e647
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,10 +22,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
// Modified to be compatible with webpack 4 / Next.js
import React from 'react'
import { useSyncExternalStore } from 'use-sync-external-store/shim'
import { LoadableContext } from './loadable-context'
const { useSyncExternalStore } = process.env.__NEXT_REACT_ROOT
? require('react')
: require('use-sync-external-store/shim')
const ALL_INITIALIZERS = []
const READY_INITIALIZERS = []
let initialized = false