Skip to content

Commit 6b8de9a

Browse files
Merge branch 'canary' into enable/i18n
2 parents 693d0e3 + 0f25051 commit 6b8de9a

File tree

3 files changed

+140
-4
lines changed

3 files changed

+140
-4
lines changed

packages/next/build/webpack/loaders/next-serverless-loader.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ const nextServerlessLoader: loader.Loader = function () {
492492
export async function renderReqToHTML(req, res, renderMode, _renderOpts, _params) {
493493
let Document
494494
let Error
495-
let NotFound
495+
let notFoundMod
496496
;[
497497
getStaticProps,
498498
getServerSideProps,
@@ -502,7 +502,7 @@ const nextServerlessLoader: loader.Loader = function () {
502502
config,
503503
{ default: Document },
504504
{ default: Error },
505-
${absolute404Path ? `{ default: NotFound }, ` : ''}
505+
${absolute404Path ? `notFoundMod, ` : ''}
506506
] = await Promise.all([
507507
getStaticProps,
508508
getServerSideProps,
@@ -772,13 +772,15 @@ const nextServerlessLoader: loader.Loader = function () {
772772
res.statusCode = 404
773773
774774
const NotFoundComponent = ${
775-
absolute404Path ? 'NotFound' : 'Error'
775+
absolute404Path ? 'notFoundMod.default' : 'Error'
776776
}
777777
778778
const errPathname = "${absolute404Path ? '/404' : '/_error'}"
779779
780780
const result = await renderToHTML(req, res, errPathname, parsedUrl.query, Object.assign({}, options, {
781-
getStaticProps: undefined,
781+
getStaticProps: ${
782+
absolute404Path ? `notFoundMod.getStaticProps` : 'undefined'
783+
},
782784
getStaticPaths: undefined,
783785
getServerSideProps: undefined,
784786
Component: NotFoundComponent,
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import Link from 'next/link'
2+
import { useRouter } from 'next/router'
3+
4+
export default function Page(props) {
5+
const router = useRouter()
6+
7+
return (
8+
<>
9+
<p id="gsp">gsp page</p>
10+
<p id="props">{JSON.stringify(props)}</p>
11+
<p id="router-locale">{router.locale}</p>
12+
<p id="router-locales">{JSON.stringify(router.locales)}</p>
13+
<p id="router-query">{JSON.stringify(router.query)}</p>
14+
<p id="router-pathname">{router.pathname}</p>
15+
<p id="router-as-path">{router.asPath}</p>
16+
<Link href="/">
17+
<a id="to-index">to /</a>
18+
</Link>
19+
<br />
20+
</>
21+
)
22+
}
23+
24+
export const getStaticProps = ({ params, locale, locales }) => {
25+
if (locale === 'en' || locale === 'nl') {
26+
return {
27+
notFound: true,
28+
}
29+
}
30+
31+
return {
32+
props: {
33+
params,
34+
locale,
35+
locales,
36+
},
37+
}
38+
}
39+
40+
export const getStaticPaths = () => {
41+
return {
42+
// the default locale will be used since one isn't defined here
43+
paths: ['first', 'second'].map((slug) => ({
44+
params: { slug },
45+
})),
46+
fallback: 'blocking',
47+
}
48+
}

test/integration/i18n-support/test/index.test.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ function runTests(isDev) {
106106
initialRevalidateSeconds: false,
107107
srcRoute: '/gsp/no-fallback/[slug]',
108108
},
109+
'/en-US/not-found/blocking-fallback/first': {
110+
dataRoute: `/_next/data/${buildId}/en-US/not-found/blocking-fallback/first.json`,
111+
initialRevalidateSeconds: false,
112+
srcRoute: '/not-found/blocking-fallback/[slug]',
113+
},
114+
'/en-US/not-found/blocking-fallback/second': {
115+
dataRoute: `/_next/data/${buildId}/en-US/not-found/blocking-fallback/second.json`,
116+
initialRevalidateSeconds: false,
117+
srcRoute: '/not-found/blocking-fallback/[slug]',
118+
},
109119
'/en-US/not-found/fallback/first': {
110120
dataRoute: `/_next/data/${buildId}/en-US/not-found/fallback/first.json`,
111121
initialRevalidateSeconds: false,
@@ -157,6 +167,18 @@ function runTests(isDev) {
157167
)}/gsp/no\\-fallback/([^/]+?)\\.json$`
158168
),
159169
},
170+
'/not-found/blocking-fallback/[slug]': {
171+
dataRoute: `/_next/data/${buildId}/not-found/blocking-fallback/[slug].json`,
172+
dataRouteRegex: normalizeRegEx(
173+
`^\\/_next\\/data\\/${escapeRegex(
174+
buildId
175+
)}\\/not\\-found\\/blocking\\-fallback\\/([^\\/]+?)\\.json$`
176+
),
177+
fallback: null,
178+
routeRegex: normalizeRegEx(
179+
`^\\/not\\-found\\/blocking\\-fallback\\/([^\\/]+?)(?:\\/)?$`
180+
),
181+
},
160182
'/not-found/fallback/[slug]': {
161183
dataRoute: `/_next/data/${buildId}/not-found/fallback/[slug].json`,
162184
dataRouteRegex: normalizeRegEx(
@@ -957,6 +979,70 @@ function runTests(isDev) {
957979
expect(await browser.eval('window.beforeNav')).toBe(1)
958980
})
959981

982+
it('should render 404 for blocking fallback page that returned 404 on client transition', async () => {
983+
const browser = await webdriver(appPort, '/en', true, true)
984+
await browser.eval(`(function() {
985+
next.router.push('/not-found/blocking-fallback/first')
986+
})()`)
987+
await browser.waitForElementByCss('h1')
988+
await browser.eval('window.beforeNav = 1')
989+
990+
expect(await browser.elementByCss('html').text()).toContain(
991+
'This page could not be found'
992+
)
993+
const props = JSON.parse(await browser.elementByCss('#props').text())
994+
995+
expect(props.is404).toBe(true)
996+
expect(props.locale).toBe('en')
997+
expect(await browser.elementByCss('html').getAttribute('lang')).toBe('en')
998+
999+
const parsedUrl = url.parse(
1000+
await browser.eval('window.location.href'),
1001+
true
1002+
)
1003+
expect(parsedUrl.pathname).toBe('/en/not-found/blocking-fallback/first')
1004+
expect(parsedUrl.query).toEqual({})
1005+
1006+
if (isDev) {
1007+
// make sure page doesn't reload un-necessarily in development
1008+
await waitFor(10 * 1000)
1009+
}
1010+
expect(await browser.eval('window.beforeNav')).toBe(1)
1011+
})
1012+
1013+
it('should render 404 for blocking fallback page that returned 404', async () => {
1014+
const browser = await webdriver(
1015+
appPort,
1016+
'/en/not-found/blocking-fallback/first',
1017+
true,
1018+
true
1019+
)
1020+
await browser.waitForElementByCss('h1')
1021+
await browser.eval('window.beforeNav = 1')
1022+
1023+
expect(await browser.elementByCss('html').text()).toContain(
1024+
'This page could not be found'
1025+
)
1026+
const props = JSON.parse(await browser.elementByCss('#props').text())
1027+
1028+
expect(props.is404).toBe(true)
1029+
expect(props.locale).toBe('en')
1030+
expect(await browser.elementByCss('html').getAttribute('lang')).toBe('en')
1031+
1032+
const parsedUrl = url.parse(
1033+
await browser.eval('window.location.href'),
1034+
true
1035+
)
1036+
expect(parsedUrl.pathname).toBe('/en/not-found/blocking-fallback/first')
1037+
expect(parsedUrl.query).toEqual({})
1038+
1039+
if (isDev) {
1040+
// make sure page doesn't reload un-necessarily in development
1041+
await waitFor(10 * 1000)
1042+
}
1043+
expect(await browser.eval('window.beforeNav')).toBe(1)
1044+
})
1045+
9601046
it('should not remove locale prefix for default locale', async () => {
9611047
const res = await fetchViaHTTP(appPort, '/en-US', undefined, {
9621048
redirect: 'manual',

0 commit comments

Comments
 (0)