Unverified Commit 34b78dc7 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Handle hmr for edge ssr in app dir (#41156)

Include the edge server changes that starting in app dir into server components changes. Most changes are merging condition `isAppPath && this.appDir` into `isAppPath`.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`
parent 51552c1a
...@@ -612,22 +612,21 @@ export default class HotReloader { ...@@ -612,22 +612,21 @@ export default class HotReloader {
onEdgeServer: () => { onEdgeServer: () => {
// TODO-APP: verify if child entry should support. // TODO-APP: verify if child entry should support.
if (!isEdgeServerCompilation || !isEntry) return if (!isEdgeServerCompilation || !isEntry) return
const appDirLoader = const appDirLoader = isAppPath
isAppPath && this.appDir ? getAppEntry({
? getAppEntry({ name: bundlePath,
name: bundlePath, appPaths: entryData.appPaths,
appPaths: entryData.appPaths, pagePath: posix.join(
pagePath: posix.join( APP_DIR_ALIAS,
APP_DIR_ALIAS, relative(
relative( this.appDir!,
this.appDir!, entryData.absolutePagePath
entryData.absolutePagePath ).replace(/\\/g, '/')
).replace(/\\/g, '/') ),
), appDir: this.appDir!,
appDir: this.appDir!, pageExtensions: this.config.pageExtensions,
pageExtensions: this.config.pageExtensions, }).import
}).import : undefined
: undefined
entries[entryKey].status = BUILDING entries[entryKey].status = BUILDING
entrypoints[bundlePath] = finalizeEntrypoint({ entrypoints[bundlePath] = finalizeEntrypoint({
...@@ -688,25 +687,24 @@ export default class HotReloader { ...@@ -688,25 +687,24 @@ export default class HotReloader {
} }
entrypoints[bundlePath] = finalizeEntrypoint({ entrypoints[bundlePath] = finalizeEntrypoint({
compilerType: 'server', compilerType: COMPILER_NAMES.server,
name: bundlePath, name: bundlePath,
isServerComponent, isServerComponent,
value: value: isAppPath
this.appDir && bundlePath.startsWith('app/') ? getAppEntry({
? getAppEntry({ name: bundlePath,
name: bundlePath, appPaths: entryData.appPaths,
appPaths: entryData.appPaths, pagePath: posix.join(
pagePath: posix.join( APP_DIR_ALIAS,
APP_DIR_ALIAS, relative(
relative( this.appDir!,
this.appDir!, entryData.absolutePagePath
entryData.absolutePagePath ).replace(/\\/g, '/')
).replace(/\\/g, '/') ),
), appDir: this.appDir!,
appDir: this.appDir!, pageExtensions: this.config.pageExtensions,
pageExtensions: this.config.pageExtensions, })
}) : relativeRequest,
: relativeRequest,
appDir: this.config.experimental.appDir, appDir: this.config.experimental.appDir,
}) })
}, },
...@@ -895,7 +893,12 @@ export default class HotReloader { ...@@ -895,7 +893,12 @@ export default class HotReloader {
changedServerPages, changedServerPages,
changedClientPages changedClientPages
) )
const edgeServerOnlyChanges = difference<string>(
changedEdgeServerPages,
changedClientPages
)
const serverComponentChanges = serverOnlyChanges const serverComponentChanges = serverOnlyChanges
.concat(edgeServerOnlyChanges)
.filter((key) => key.startsWith('app/')) .filter((key) => key.startsWith('app/'))
.concat(Array.from(changedCSSImportPages)) .concat(Array.from(changedCSSImportPages))
const pageChanges = serverOnlyChanges.filter((key) => const pageChanges = serverOnlyChanges.filter((key) =>
......
import { createNext, FileRef } from 'e2e-utils' import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base' import { NextInstance } from 'test/lib/next-modes/base'
import { renderViaHTTP } from 'next-test-utils' import { check, renderViaHTTP } from 'next-test-utils'
import path from 'path' import path from 'path'
describe('app-dir edge SSR', () => { describe('app-dir edge SSR', () => {
...@@ -37,4 +37,26 @@ describe('app-dir edge SSR', () => { ...@@ -37,4 +37,26 @@ describe('app-dir edge SSR', () => {
const pageHtml = await renderViaHTTP(next.url, '/pages-edge') const pageHtml = await renderViaHTTP(next.url, '/pages-edge')
expect(pageHtml).toContain('<p>pages-edge-ssr</p>') expect(pageHtml).toContain('<p>pages-edge-ssr</p>')
}) })
if ((globalThis as any).isNextDev) {
it('should handle edge rsc hmr', async () => {
const pageFile = 'app/app-edge/page.tsx'
const content = await next.readFile(pageFile)
// Update rendered content
const updatedContent = content.replace('app-edge-ssr', 'edge-hmr')
await next.patchFile(pageFile, updatedContent)
await check(async () => {
const html = await renderViaHTTP(next.url, '/app-edge')
return html
}, /edge-hmr/)
// Revert
await next.patchFile(pageFile, content)
await check(async () => {
const html = await renderViaHTTP(next.url, '/app-edge')
return html
}, /app-edge-ssr/)
})
}
}) })
'client' 'client'
// TODO-APP: support typing for useSelectedLayoutSegment
// @ts-ignore
import { useSelectedLayoutSegment } from 'next/dist/client/components/hooks-client' import { useSelectedLayoutSegment } from 'next/dist/client/components/hooks-client'
export default function Layout({ children }: { children: React.ReactNode }) { export default function Layout({ children }: { children: React.ReactNode }) {
......
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