Skip to content

Commit

Permalink
fix(vercel#40388): only add default loading for non-suspense
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Sep 9, 2022
1 parent 9ab5c01 commit 75c9a2c
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions packages/next/shared/lib/dynamic.tsx
Expand Up @@ -65,29 +65,33 @@ export default function dynamic<P = {}>(
options?: DynamicOptions<P>
): React.ComponentType<P> {
let loadableFn: LoadableFn<P> = Loadable
let loadableOptions: LoadableOptions<P> = {
// 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<P> = 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 (
<p>
{error.message}
<br />
{error.stack}
</p>
)
}
}

return null
}
if (error) {
return (
<p>
{error.message}
<br />
{error.stack}
</p>
)
}
},
}

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'))
Expand Down

0 comments on commit 75c9a2c

Please sign in to comment.