Skip to content

Commit

Permalink
Mark dynamic as client component (#38574)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
huozhi and kodiakhq[bot] committed Jul 13, 2022
1 parent d403218 commit 6b578f0
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/next/build/webpack/loaders/utils.ts
@@ -1,6 +1,6 @@
export const defaultJsFileExtensions = ['js', 'mjs', 'jsx', 'ts', 'tsx']
const imageExtensions = ['jpg', 'jpeg', 'png', 'webp', 'avif']
const nextClientComponents = ['link', 'image', 'head', 'script']
const nextClientComponents = ['link', 'image', 'head', 'script', 'dynamic']

const NEXT_BUILT_IN_CLIENT_RSC_REGEX = new RegExp(
`[\\\\/]next[\\\\/](${nextClientComponents.join('|')})\\.js$`
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/app-dir/app/app/dashboard/index/dynamic.client.js
@@ -0,0 +1,11 @@
import { useState } from 'react'
import styles from './dynamic.module.css'

export default function Dynamic() {
let [state] = useState('next dynamic')
return (
<p id="css-text-dynamic" className={styles.dynamic}>
hello from modern the {state}
</p>
)
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/app/app/dashboard/index/dynamic.module.css
@@ -0,0 +1,3 @@
.dynamic {
color: blue;
}
6 changes: 5 additions & 1 deletion test/e2e/app-dir/app/app/dashboard/index/lazy.client.js
@@ -1,7 +1,11 @@
import styles from './lazy.module.css'

export default function LazyComponent() {
return (
<>
<p>hello from lazy</p>
<p id="css-text-lazy" className={styles.lazy}>
hello from lazy
</p>
</>
)
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/app/app/dashboard/index/lazy.module.css
@@ -0,0 +1,3 @@
.lazy {
color: purple;
}
@@ -0,0 +1,7 @@
import dynamic from 'next/dynamic'

const Dynamic = dynamic(() => import('./dynamic.client'))

export function NextDynamicClientComponent() {
return <Dynamic />
}
6 changes: 4 additions & 2 deletions test/e2e/app-dir/app/app/dashboard/index/page.server.js
@@ -1,10 +1,12 @@
import { ClientComponent } from './test.client.js'
import { LazyClientComponent } from './react-lazy.client'
import { NextDynamicClientComponent } from './next-dynamic.client'

export default function DashboardIndexPage() {
return (
<>
<p>hello from app/dashboard/index</p>
<ClientComponent />
<NextDynamicClientComponent />
<LazyClientComponent />
</>
)
}
Expand Up @@ -2,7 +2,7 @@ import { useState, lazy } from 'react'

const Lazy = lazy(() => import('./lazy.client.js'))

export function ClientComponent() {
export function LazyClientComponent() {
let [state] = useState('client')
return (
<>
Expand Down
19 changes: 16 additions & 3 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -64,11 +64,24 @@ describe('app dir', () => {
it('should serve /index as separate page', async () => {
const html = await renderViaHTTP(next.url, '/dashboard/index')
expect(html).toContain('hello from app/dashboard/index')
// should load chunks generated via async import correctly
expect(html).toContain('hello from lazy')
})

it('should load chunks generated via async import correctly', async () => {
const html = await renderViaHTTP(next.url, '/dashboard/index')
expect(html).toContain('hello from lazy')
// TODO-APP: handle css modules fouc in dev
it.skip('should handle css imports in next/dynamic correctly', async () => {
const browser = await webdriver(next.url, '/dashboard/index')

expect(
await browser.eval(
`window.getComputedStyle(document.querySelector('#css-text-dynamic')).color`
)
).toBe('rgb(0, 0, 255)')
expect(
await browser.eval(
`window.getComputedStyle(document.querySelector('#css-text-lazy')).color`
)
).toBe('rgb(128, 0, 128)')
})

it('should include layouts when no direct parent layout', async () => {
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/app-dir/rsc-basic.test.ts
Expand Up @@ -361,7 +361,9 @@ describe('app dir - react server components', () => {
expect(gotInlinedData).toBe(true)
}
)
})

it('should support partial hydration with inlined server data in browser', async () => {
// Should end up with "next_streaming_data".
const browser = await webdriver(next.url, '/partial-hydration', {
waitHydration: false,
Expand Down

0 comments on commit 6b578f0

Please sign in to comment.