diff --git a/packages/next/shared/lib/dynamic.tsx b/packages/next/shared/lib/dynamic.tsx index 6e7dc8fa2290..094e11faf0fd 100644 --- a/packages/next/shared/lib/dynamic.tsx +++ b/packages/next/shared/lib/dynamic.tsx @@ -65,29 +65,33 @@ export default function dynamic

( options?: DynamicOptions

): React.ComponentType

{ let loadableFn: LoadableFn

= Loadable - let loadableOptions: LoadableOptions

= { - // A loading component is not required, so we default it - loading: ({ error, isLoading, pastDelay }) => { - if (!pastDelay) return null - if (process.env.NODE_ENV === 'development') { - if (isLoading) { + + let loadableOptions: LoadableOptions

= options?.suspense + ? {} + : // only provide a default loading component when suspense is disabled + { + // A loading component is not required, so we default it + loading: ({ error, isLoading, pastDelay }) => { + if (!pastDelay) return null + if (process.env.NODE_ENV === 'development') { + if (isLoading) { + return null + } + if (error) { + return ( +

+ {error.message} +
+ {error.stack} +

+ ) + } + } + return null - } - if (error) { - return ( -

- {error.message} -
- {error.stack} -

- ) - } + }, } - return null - }, - } - // Support for direct import(), eg: dynamic(import('../hello-world')) // Note that this is only kept for the edge case where someone is passing in a promise as first argument // The react-loadable babel plugin will turn dynamic(import('../hello-world')) into dynamic(() => import('../hello-world'))