Skip to content

Commit

Permalink
test: both wrapped and unwrapped dynamic() (#69780)
Browse files Browse the repository at this point in the history
We should be testing both usage patterns, i.e. returning a component
wrapped in a `{ default: ... }` and just a bare component.

Note that the behavior here will partially change in 15, so this test is
just so that we can avoid regressing in 14.x.
  • Loading branch information
lubieowoce authored Sep 6, 2024
1 parent a882e6e commit 86547db
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use client'

export function Button(props) {
return <button {...props} />
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import dynamic from 'next/dynamic'

const Button = dynamic(() =>
import('./client').then((mod) => {
return mod.Button
})
)

export default function Page() {
return <Button id="client-button">this is a client button</Button>
}
2 changes: 1 addition & 1 deletion test/e2e/app-dir/dynamic/app/dynamic/named-export/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dynamic from 'next/dynamic'

const Button = dynamic(() =>
import('./client').then((mod) => {
return mod.Button
return { default: mod.Button }
})
)

Expand Down
5 changes: 5 additions & 0 deletions test/e2e/app-dir/dynamic/dynamic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ createNextDescribe(
expect($('h1').text()).toBe('hello')
})

it('14.x behavior: should support dynamic import that returns a client component not wrapped in a module', async () => {
const $ = await next.render$('/dynamic/named-export-unwrapped')
expect($('#client-button').text()).toBe('this is a client button')
})

describe('no SSR', () => {
it('should not render client component imported through ssr: false in client components in edge runtime', async () => {
// noSSR should not show up in html
Expand Down

0 comments on commit 86547db

Please sign in to comment.