Unverified Commit 6b578f08 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Mark dynamic as client component (#38574)

Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent d403218c
export const defaultJsFileExtensions = ['js', 'mjs', 'jsx', 'ts', 'tsx'] export const defaultJsFileExtensions = ['js', 'mjs', 'jsx', 'ts', 'tsx']
const imageExtensions = ['jpg', 'jpeg', 'png', 'webp', 'avif'] 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( const NEXT_BUILT_IN_CLIENT_RSC_REGEX = new RegExp(
`[\\\\/]next[\\\\/](${nextClientComponents.join('|')})\\.js$` `[\\\\/]next[\\\\/](${nextClientComponents.join('|')})\\.js$`
......
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>
)
}
import styles from './lazy.module.css'
export default function LazyComponent() { export default function LazyComponent() {
return ( return (
<> <>
<p>hello from lazy</p> <p id="css-text-lazy" className={styles.lazy}>
hello from lazy
</p>
</> </>
) )
} }
import dynamic from 'next/dynamic'
const Dynamic = dynamic(() => import('./dynamic.client'))
export function NextDynamicClientComponent() {
return <Dynamic />
}
import { ClientComponent } from './test.client.js' import { LazyClientComponent } from './react-lazy.client'
import { NextDynamicClientComponent } from './next-dynamic.client'
export default function DashboardIndexPage() { export default function DashboardIndexPage() {
return ( return (
<> <>
<p>hello from app/dashboard/index</p> <p>hello from app/dashboard/index</p>
<ClientComponent /> <NextDynamicClientComponent />
<LazyClientComponent />
</> </>
) )
} }
...@@ -2,7 +2,7 @@ import { useState, lazy } from 'react' ...@@ -2,7 +2,7 @@ import { useState, lazy } from 'react'
const Lazy = lazy(() => import('./lazy.client.js')) const Lazy = lazy(() => import('./lazy.client.js'))
export function ClientComponent() { export function LazyClientComponent() {
let [state] = useState('client') let [state] = useState('client')
return ( return (
<> <>
......
...@@ -64,11 +64,24 @@ describe('app dir', () => { ...@@ -64,11 +64,24 @@ describe('app dir', () => {
it('should serve /index as separate page', async () => { it('should serve /index as separate page', async () => {
const html = await renderViaHTTP(next.url, '/dashboard/index') const html = await renderViaHTTP(next.url, '/dashboard/index')
expect(html).toContain('hello from app/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 () => { // TODO-APP: handle css modules fouc in dev
const html = await renderViaHTTP(next.url, '/dashboard/index') it.skip('should handle css imports in next/dynamic correctly', async () => {
expect(html).toContain('hello from lazy') 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 () => { it('should include layouts when no direct parent layout', async () => {
......
...@@ -361,7 +361,9 @@ describe('app dir - react server components', () => { ...@@ -361,7 +361,9 @@ describe('app dir - react server components', () => {
expect(gotInlinedData).toBe(true) expect(gotInlinedData).toBe(true)
} }
) )
})
it('should support partial hydration with inlined server data in browser', async () => {
// Should end up with "next_streaming_data". // Should end up with "next_streaming_data".
const browser = await webdriver(next.url, '/partial-hydration', { const browser = await webdriver(next.url, '/partial-hydration', {
waitHydration: false, waitHydration: false,
......
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