Unverified Commit 37587162 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Handle empty module from the next dynamic loader (#44873)

parent ef9a152b
...@@ -30,7 +30,7 @@ export type DynamicOptionsLoadingProps = { ...@@ -30,7 +30,7 @@ export type DynamicOptionsLoadingProps = {
// Also for backward compatible since next/dynamic allows to resolve a component directly with loader // 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. // Client component reference proxy need to be converted to a module.
function convertModule<P>(mod: React.ComponentType<P> | ComponentModule<P>) { function convertModule<P>(mod: React.ComponentType<P> | ComponentModule<P>) {
return { default: (mod as ComponentModule<P>).default || mod } return { default: (mod as ComponentModule<P>)?.default || mod }
} }
export type DynamicOptions<P = {}> = LoadableGeneratedOptions & { export type DynamicOptions<P = {}> = LoadableGeneratedOptions & {
......
import { check, getRedboxSource, hasRedbox } from 'next-test-utils' import {
check,
getRedboxDescription,
getRedboxSource,
hasRedbox,
} from 'next-test-utils'
import { createNextDescribe } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
if (!(globalThis as any).isNextDev) { if (!(globalThis as any).isNextDev) {
...@@ -133,6 +138,15 @@ if (!(globalThis as any).isNextDev) { ...@@ -133,6 +138,15 @@ if (!(globalThis as any).isNextDev) {
`You're importing a component that needs server-only. That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component.` `You're importing a component that needs server-only. That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component.`
) )
}) })
it('should error for invalid undefined module retuning from next dynamic', async () => {
const browser = await next.browser('/client-with-errors/dynamic')
await hasRedbox(browser)
expect(await getRedboxDescription(browser)).toContain(
`Element type is invalid. Received a promise that resolves to: undefined. Lazy element type must resolve to a class or function.`
)
})
} }
) )
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment