Unverified Commit a0a18a23 authored by Will Binns-Smith's avatar Will Binns-Smith Committed by GitHub

Turbopack: restrict server HMR to app pages (#90663)

App router types like routes go through the traditional `require` route
bypassing the Turbopack runtime, so they aren't easily solved with
server HMR right now.

Test Plan: Added an e2e test.

---------
Co-authored-by: 's avatarvercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
parent 96512309
...@@ -592,13 +592,22 @@ export async function createHotReloaderTurbopack( ...@@ -592,13 +592,22 @@ export async function createHotReloaderTurbopack(
join(distDir, p) join(distDir, p)
) )
const { type: entryType } = splitEntryKey(key) const { type: entryType, page: entryPage } = splitEntryKey(key)
// Server HMR only applies to App Router. const isAppPage =
// Pages Router uses Node's require(), root entries (middleware/instrumentation) entryType === 'app' &&
// use the edge runtime. currentEntrypoints.app.get(entryPage)?.type === 'app-page'
// Server HMR only applies to app router pages since these use the Turbopack runtime.
// Currently, this is only app router pages.
//
// This excludes:
// - Pages Router pages
// - Edge routes
// - Middleware
// - App Router route handlers (route.ts)
const usesServerHmr = const usesServerHmr =
experimentalServerFastRefresh && experimentalServerFastRefresh &&
entryType === 'app' && isAppPage &&
writtenEndpoint.type !== 'edge' writtenEndpoint.type !== 'edge'
for (const file of serverPaths) { for (const file of serverPaths) {
......
export async function GET() {
return new Response('version: 0')
}
import type { Response } from 'node-fetch'
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils' import { retry } from 'next-test-utils'
...@@ -154,4 +155,28 @@ describe('server-hmr', () => { ...@@ -154,4 +155,28 @@ describe('server-hmr', () => {
} }
) )
}) })
describe('route handler hmr', () => {
function getText(res: Response) {
return res.ok
? res.text()
: Promise.reject(
new Error('Failed to fetch route handler: ' + res.status)
)
}
it('reflects route handler changes on fetch/refresh', async () => {
const initial = await next.fetch('/api/hello').then(getText)
expect(initial).toBe('version: 0')
await next.patchFile('app/api/hello/route.ts', (content) =>
content.replace('version: 0', 'version: 1')
)
await retry(async () => {
const updated = await next.fetch('/api/hello').then(getText)
expect(updated).toBe('version: 1')
})
})
})
}) })
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