import { Suspense, Fragment, lazy } from 'react' import { BailoutToCSR } from './dynamic-bailout-to-csr' import type { ComponentModule } from './types' import { PreloadChunks } from './preload-chunks' // Normalize loader to return the module as form { default: Component } for `React.lazy`. // Also for backward compatible since next/dynamic allows to resolve a component directly with loader // Client component reference proxy need to be converted to a module. function convertModule
( mod: React.ComponentType
| ComponentModule
| undefined ): { default: React.ComponentType
} { // Check "default" prop before accessing it, as it could be client reference proxy that could break it reference. // Cases: // mod: { default: Component } // mod: Component // mod: { default: proxy(Component) } // mod: proxy(Component) const hasDefault = mod && 'default' in mod return { default: hasDefault ? (mod as ComponentModule
).default : (mod as React.ComponentType
),
}
}
const defaultOptions = {
loader: () => Promise.resolve(convertModule(() => null)),
loading: null,
ssr: true,
}
interface LoadableOptions {
loader?: () => Promise