Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle hmr for edge ssr in app dir #41156

Merged
merged 1 commit into from Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 36 additions & 33 deletions packages/next/server/dev/hot-reloader.ts
Expand Up @@ -612,22 +612,21 @@ export default class HotReloader {
onEdgeServer: () => {
// TODO-APP: verify if child entry should support.
if (!isEdgeServerCompilation || !isEntry) return
const appDirLoader =
isAppPath && this.appDir
? getAppEntry({
name: bundlePath,
appPaths: entryData.appPaths,
pagePath: posix.join(
APP_DIR_ALIAS,
relative(
this.appDir!,
entryData.absolutePagePath
).replace(/\\/g, '/')
),
appDir: this.appDir!,
pageExtensions: this.config.pageExtensions,
}).import
: undefined
const appDirLoader = isAppPath
? getAppEntry({
name: bundlePath,
appPaths: entryData.appPaths,
pagePath: posix.join(
APP_DIR_ALIAS,
relative(
this.appDir!,
entryData.absolutePagePath
).replace(/\\/g, '/')
),
appDir: this.appDir!,
pageExtensions: this.config.pageExtensions,
}).import
: undefined

entries[entryKey].status = BUILDING
entrypoints[bundlePath] = finalizeEntrypoint({
Expand Down Expand Up @@ -688,25 +687,24 @@ export default class HotReloader {
}

entrypoints[bundlePath] = finalizeEntrypoint({
compilerType: 'server',
compilerType: COMPILER_NAMES.server,
name: bundlePath,
isServerComponent,
value:
this.appDir && bundlePath.startsWith('app/')
? getAppEntry({
name: bundlePath,
appPaths: entryData.appPaths,
pagePath: posix.join(
APP_DIR_ALIAS,
relative(
this.appDir!,
entryData.absolutePagePath
).replace(/\\/g, '/')
),
appDir: this.appDir!,
pageExtensions: this.config.pageExtensions,
})
: relativeRequest,
value: isAppPath
? getAppEntry({
name: bundlePath,
appPaths: entryData.appPaths,
pagePath: posix.join(
APP_DIR_ALIAS,
relative(
this.appDir!,
entryData.absolutePagePath
).replace(/\\/g, '/')
),
appDir: this.appDir!,
pageExtensions: this.config.pageExtensions,
})
: relativeRequest,
appDir: this.config.experimental.appDir,
})
},
Expand Down Expand Up @@ -895,7 +893,12 @@ export default class HotReloader {
changedServerPages,
changedClientPages
)
const edgeServerOnlyChanges = difference<string>(
changedEdgeServerPages,
changedClientPages
)
const serverComponentChanges = serverOnlyChanges
.concat(edgeServerOnlyChanges)
.filter((key) => key.startsWith('app/'))
.concat(Array.from(changedCSSImportPages))
const pageChanges = serverOnlyChanges.filter((key) =>
Expand Down
24 changes: 23 additions & 1 deletion test/e2e/app-dir/app-edge.test.ts
@@ -1,6 +1,6 @@
import { createNext, FileRef } from 'e2e-utils'
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'

describe('app-dir edge SSR', () => {
Expand Down Expand Up @@ -37,4 +37,26 @@ describe('app-dir edge SSR', () => {
const pageHtml = await renderViaHTTP(next.url, '/pages-edge')
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/)
})
}
})
2 changes: 2 additions & 0 deletions test/e2e/app-dir/app-edge/app/app-edge/layout.tsx
@@ -1,5 +1,7 @@
'client'

// TODO-APP: support typing for useSelectedLayoutSegment
// @ts-ignore
import { useSelectedLayoutSegment } from 'next/dist/client/components/hooks-client'

export default function Layout({ children }: { children: React.ReactNode }) {
Expand Down