Unverified Commit 62c7eff3 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Revert "Revert "Refactor Server Router" (#40328)" (#40333)

This unreverts https://github.com/vercel/next.js/pull/40328 as it wasn't
the cause for https://github.com/vercel/next.js/issues/40241 like
initially suspected and the actual fix has been included here as well
with regression test.

Fixes: https://github.com/vercel/next.js/issues/40241

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
parent b86bf075
...@@ -959,7 +959,11 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -959,7 +959,11 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// Toggle whether or not this is a Data request // Toggle whether or not this is a Data request
const isDataReq = const isDataReq =
!!(query.__nextDataReq || req.headers['x-nextjs-data']) && !!(
query.__nextDataReq ||
(req.headers['x-nextjs-data'] &&
(this.serverOptions as any).webServerConfig)
) &&
(isSSG || hasServerProps || isServerComponent) (isSSG || hasServerProps || isServerComponent)
delete query.__nextDataReq delete query.__nextDataReq
......
...@@ -221,7 +221,6 @@ export default class DevServer extends Server { ...@@ -221,7 +221,6 @@ export default class DevServer extends Server {
for (const path in exportPathMap) { for (const path in exportPathMap) {
const { page, query = {} } = exportPathMap[path] const { page, query = {} } = exportPathMap[path]
// We use unshift so that we're sure the routes is defined before Next's default routes
this.router.addFsRoute({ this.router.addFsRoute({
match: getPathMatch(path), match: getPathMatch(path),
type: 'route', type: 'route',
......
This diff is collapsed.
...@@ -324,6 +324,12 @@ describe('should set-up next', () => { ...@@ -324,6 +324,12 @@ describe('should set-up next', () => {
it('should de-dupe HTML/data requests', async () => { it('should de-dupe HTML/data requests', async () => {
const res = await fetchViaHTTP(appPort, '/gsp', undefined, { const res = await fetchViaHTTP(appPort, '/gsp', undefined, {
redirect: 'manual', redirect: 'manual',
headers: {
// ensure the nextjs-data header being present
// doesn't incorrectly return JSON for HTML path
// during prerendering
'x-nextjs-data': '1',
},
}) })
expect(res.status).toBe(200) expect(res.status).toBe(200)
expect(res.headers.get('x-nextjs-cache')).toBeFalsy() expect(res.headers.get('x-nextjs-cache')).toBeFalsy()
......
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