Unverified Commit 42633188 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure i18n context values are provided for blocking 404 (#18513)

This ensures we provide the current `locale`, `locales`, and `defaultLocale` in the context when rendering the 404 for a blocking SSG page

Fixes: https://github.com/vercel/next.js/issues/18505
parent 629884af
......@@ -784,7 +784,10 @@ const nextServerlessLoader: loader.Loader = function () {
getStaticPaths: undefined,
getServerSideProps: undefined,
Component: NotFoundComponent,
err: undefined
err: undefined,
locale: detectedLocale,
locales,
defaultLocale: i18n.defaultLocale,
}))
sendPayload(req, res, result, 'html', ${
......
......@@ -7,10 +7,12 @@ export default function NotFound(props) {
)
}
export const getStaticProps = ({ locale }) => {
export const getStaticProps = ({ locale, locales, defaultLocale }) => {
return {
props: {
locale,
locales,
defaultLocale,
is404: true,
},
}
......
/* eslint-env jest */
import http from 'http'
import url from 'url'
import fs from 'fs-extra'
import cheerio from 'cheerio'
......@@ -17,6 +18,7 @@ import {
File,
waitFor,
normalizeRegEx,
getPageFileFromPagesManifest,
} from 'next-test-utils'
jest.setTimeout(1000 * 60 * 2)
......@@ -1688,6 +1690,48 @@ describe('i18n Support', () => {
await killApp(app)
})
it('should have correct props for blocking notFound', async () => {
const serverFile = getPageFileFromPagesManifest(
appDir,
'/not-found/blocking-fallback/[slug]'
)
const appPort = await findPort()
const mod = require(join(appDir, '.next/serverless', serverFile))
const server = http.createServer(async (req, res) => {
try {
await mod.render(req, res)
} catch (err) {
res.statusCode = 500
res.end('internal err')
}
})
await new Promise((resolve, reject) => {
server.listen(appPort, (err) => (err ? reject(err) : resolve()))
})
console.log('listening on', appPort)
const res = await fetchViaHTTP(
appPort,
'/nl/not-found/blocking-fallback/first'
)
server.close()
expect(res.status).toBe(404)
const $ = cheerio.load(await res.text())
const props = JSON.parse($('#props').text())
expect($('#not-found').text().length > 0).toBe(true)
expect(props).toEqual({
is404: true,
locale: 'nl',
locales,
defaultLocale: 'en-US',
})
})
runTests()
})
})
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