Skip to content

Commit c575469

Browse files
authored
minimal 404 to fix 500s (#57267)
1 parent 9155e26 commit c575469

File tree

2 files changed

+8
-28
lines changed

2 files changed

+8
-28
lines changed

src/frame/middleware/render-page.ts

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { get } from 'lodash-es'
55

66
import getMiniTocItems from '@/frame/lib/get-mini-toc-items'
77
import patterns from '@/frame/lib/patterns'
8-
import { pathLanguagePrefixed } from '@/languages/lib/languages'
98
import FailBot from '@/observability/lib/failbot'
109
import statsd from '@/observability/lib/statsd'
1110
import type { ExtendedRequest } from '@/types'
@@ -16,7 +15,6 @@ import { isConnectionDropped } from './halt-on-dropped-connection'
1615
import { nextHandleRequest } from './next'
1716

1817
const STATSD_KEY_RENDER = 'middleware.render_page'
19-
const STATSD_KEY_404 = 'middleware.render_404'
2018

2119
async function buildRenderedPage(req: ExtendedRequest): Promise<string> {
2220
const { context } = req
@@ -69,33 +67,10 @@ export default async function renderPage(req: ExtendedRequest, res: Response) {
6967
)
7068
}
7169

72-
if (!pathLanguagePrefixed(req.path)) {
73-
defaultCacheControl(res)
74-
return res.status(404).type('html').send(minimumNotFoundHtml)
75-
}
76-
77-
// For App Router migration: All language-prefixed 404s should use App Router
78-
statsd.increment(STATSD_KEY_404, 1, [
79-
`url:${req.url}`,
80-
`path:${req.path}`,
81-
`referer:${req.headers.referer || ''}`,
82-
])
83-
70+
// send minimal 404 at this point since we ran into hydration issues trying to pass
71+
// these along to AppRouter 404 handling
8472
defaultCacheControl(res)
85-
86-
// Create a mock request that will be handled by App Router
87-
const mockReq = Object.create(req)
88-
mockReq.url = '/404'
89-
mockReq.path = '/404'
90-
mockReq.method = 'GET'
91-
92-
// Only pass pathname
93-
res.setHeader('x-pathname', req.path)
94-
95-
// Import nextApp and handle directly
96-
const { nextApp } = await import('./next')
97-
res.status(404)
98-
return nextApp.getRequestHandler()(mockReq, res)
73+
return res.status(404).type('html').send(minimumNotFoundHtml)
9974
}
10075

10176
// Just finish fast without all the details like Content-Length

src/frame/tests/server.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ describe('server', () => {
9090
expect($.res.statusCode).toBe(404)
9191
})
9292

93+
test('renders a 404 for language prefixed versioned non-existent pages', async () => {
94+
const res = await get('/en/enterprise-cloud@latest/nonexistent-page')
95+
expect(res.statusCode).toBe(404)
96+
})
97+
9398
// When using `got()` to send full end-to-end URLs, you can't use
9499
// URLs like in this test because got will
95100
// throw `RequestError: URI malformed`.

0 commit comments

Comments
 (0)