Skip to content

Commit

Permalink
suspense -> unstable_suspense
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Aug 10, 2021
1 parent 574d900 commit 2212dcb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
16 changes: 8 additions & 8 deletions packages/next/shared/lib/dynamic.tsx
Expand Up @@ -34,7 +34,7 @@ export type LoadableBaseOptions<P = {}> = LoadableGeneratedOptions & {
| React.LazyExoticComponent<React.ComponentType<P>>
loadableGenerated?: LoadableGeneratedOptions
ssr?: boolean
suspense?: boolean
unstable_suspense?: boolean
}

export type LoadableOptions<P = {}> = LoadableBaseOptions<P>
Expand Down Expand Up @@ -115,25 +115,25 @@ export default function dynamic<P = {}>(
if (!process.env.__NEXT_REACT_ROOT) {
if (
process.env.NODE_ENV !== 'production' &&
loadableOptions.suspense &&
loadableOptions.unstable_suspense &&
!isServerSide
) {
console.warn(
`Enable experimental.reactRoot or use React version above 18 to use suspense option`
)
}
loadableOptions.suspense = false
loadableOptions.unstable_suspense = false
}

const { suspense, loader } = loadableOptions
// If suspense is enabled, delegate rendering to suspense
if (suspense) {
const { unstable_suspense, loader } = loadableOptions
// If unstable_suspense is enabled, delegate rendering to unstable_suspense
if (unstable_suspense) {
delete loadableOptions.loadableGenerated
delete loadableOptions.loading
delete loadableOptions.ssr
}

if (typeof loadableOptions.loader === 'function' && suspense) {
if (typeof loadableOptions.loader === 'function' && unstable_suspense) {
loadableOptions.loader = React.lazy(
loader as () => Promise<{
default: React.ComponentType<P>
Expand All @@ -150,7 +150,7 @@ export default function dynamic<P = {}>(
}

// support for disabling server side rendering, eg: dynamic(import('../hello-world'), {ssr: false})
if (loadableOptions.ssr === false && !suspense) {
if (loadableOptions.ssr === false && !unstable_suspense) {
return noSSR(loadableFn, loadableOptions)
}

Expand Down
5 changes: 4 additions & 1 deletion packages/next/shared/lib/loadable.js
Expand Up @@ -66,11 +66,14 @@ function createLoadableComponent(loadFn, options) {
timeout: null,
webpack: null,
modules: null,
suspense: false,
unstable_suspense: false,
},
options
)

opts.suspense = opts.unstable_suspense
delete opts.unstable_suspense

let subscription = null
function init() {
if (opts.suspense) {
Expand Down

0 comments on commit 2212dcb

Please sign in to comment.