Skip to content

Commit

Permalink
build: import useSyncExternalStore from react when using react 18 (#3…
Browse files Browse the repository at this point in the history
…7212)

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`
  • Loading branch information
huozhi committed May 26, 2022
1 parent 6a5bdb5 commit 4340b4e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/next/shared/lib/loadable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4340b4e

Please sign in to comment.