Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
69524c29
Unverified
Commit
69524c29
authored
Jan 21, 2022
by
JJ Kasper
Committed by
GitHub
Jan 21, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix static file check with i18n (#33503)
parent
557a9725
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
6 deletions
+45
-6
base-server.ts
packages/next/server/base-server.ts
+6
-3
next-dev-server.ts
packages/next/server/dev/next-dev-server.ts
+1
-1
next-server.ts
packages/next/server/next-server.ts
+4
-2
router.ts
packages/next/server/router.ts
+13
-0
shared.js
test/integration/i18n-support/test/shared.js
+21
-0
No files found.
packages/next/server/base-server.ts
View file @
69524c29
...
...
@@ -740,7 +740,8 @@ export default abstract class Server {
res,
pathname,
{ ..._parsedUrl.query, _nextDataReq: '1' },
parsedUrl
parsedUrl,
true
)
return {
finished: true,
...
...
@@ -962,7 +963,7 @@ export default abstract class Server {
}
try {
await this.render(req, res, pathname, query, parsedUrl)
await this.render(req, res, pathname, query, parsedUrl
, true
)
return {
finished: true,
...
...
@@ -1183,7 +1184,8 @@ export default abstract class Server {
res: BaseNextResponse,
pathname: string,
query: NextParsedUrlQuery = {},
parsedUrl?: NextUrlWithParsedQuery
parsedUrl?: NextUrlWithParsedQuery,
internalRender = false
): Promise<void> {
if (!pathname.startsWith('/')) {
console.warn(
...
...
@@ -1206,6 +1208,7 @@ export default abstract class Server {
// we don't modify the URL for _next/data request but still
// call render so we special case this to prevent an infinite loop
if (
!internalRender &&
!this.minimalMode &&
!query._nextDataReq &&
(req.url?.match(/^\/_next\//) ||
...
...
packages/next/server/dev/next-dev-server.ts
View file @
69524c29
...
...
@@ -216,7 +216,7 @@ export default class DevServer extends Server {
const
mergedQuery
=
{
...
urlQuery
,
...
query
}
await
this
.
render
(
req
,
res
,
page
,
mergedQuery
,
parsedUrl
)
await
this
.
render
(
req
,
res
,
page
,
mergedQuery
,
parsedUrl
,
true
)
return
{
finished
:
true
,
}
...
...
packages/next/server/next-server.ts
View file @
69524c29
...
...
@@ -601,14 +601,16 @@ export default class NextNodeServer extends BaseServer {
res
:
BaseNextResponse
|
ServerResponse
,
pathname
:
string
,
query
?:
NextParsedUrlQuery
,
parsedUrl
?:
NextUrlWithParsedQuery
parsedUrl
?:
NextUrlWithParsedQuery
,
internal
=
false
):
Promise
<
void
>
{
return
super
.
render
(
this
.
normalizeReq
(
req
),
this
.
normalizeRes
(
res
),
pathname
,
query
,
parsedUrl
parsedUrl
,
internal
)
}
...
...
packages/next/server/router.ts
View file @
69524c29
...
...
@@ -78,6 +78,7 @@ export default class Router {
dynamicRoutes
:
DynamicRoutes
useFileSystemPublicRoutes
:
boolean
locales
:
string
[]
seenRequests
:
Set
<
any
>
constructor
({
basePath
=
''
,
...
...
@@ -123,6 +124,7 @@ export default class Router {
this
.
dynamicRoutes
=
dynamicRoutes
this
.
useFileSystemPublicRoutes
=
useFileSystemPublicRoutes
this
.
locales
=
locales
this
.
seenRequests
=
new
Set
()
}
setDynamicRoutes
(
routes
:
DynamicRoutes
=
[])
{
...
...
@@ -138,6 +140,13 @@ export default class Router {
res
:
BaseNextResponse
,
parsedUrl
:
NextUrlWithParsedQuery
):
Promise
<
boolean
>
{
if
(
this
.
seenRequests
.
has
(
req
))
{
throw
new
Error
(
`Invariant: request has already been processed:
${
req
.
url
}
, this is an internal error please open an issue.`
)
}
this
.
seenRequests
.
add
(
req
)
// memoize page check calls so we don't duplicate checks for pages
const
pageChecks
:
{
[
name
:
string
]:
Promise
<
boolean
>
}
=
{}
const
memoizedPageChecker
=
async
(
p
:
string
):
Promise
<
boolean
>
=>
{
...
...
@@ -360,6 +369,7 @@ export default class Router {
)
{
if
(
requireBasePath
)
{
// consider this a non-match so the 404 renders
this
.
seenRequests
.
delete
(
req
)
return
false
}
// page checker occurs before rewrites so we need to continue
...
...
@@ -374,6 +384,7 @@ export default class Router {
// The response was handled
if
(
result
.
finished
)
{
this
.
seenRequests
.
delete
(
req
)
return
true
}
...
...
@@ -397,11 +408,13 @@ export default class Router {
// check filesystem
if
(
testRoute
.
check
===
true
)
{
if
(
await
applyCheckTrue
(
parsedUrlUpdated
))
{
this
.
seenRequests
.
delete
(
req
)
return
true
}
}
}
}
this
.
seenRequests
.
delete
(
req
)
return
false
}
}
test/integration/i18n-support/test/shared.js
View file @
69524c29
/* eslint-env jest */
import
url
from
'url'
import
glob
from
'glob'
import
fs
from
'fs-extra'
import
cheerio
from
'cheerio'
import
{
join
}
from
'path'
...
...
@@ -56,6 +57,26 @@ export function runTests(ctx) {
})
}
it
(
'should 404 for locale prefixed static assets correctly'
,
async
()
=>
{
const
assets
=
glob
.
sync
(
'**/*.js'
,
{
cwd
:
join
(
ctx
.
appDir
,
'.next/static'
),
})
for
(
const
locale
of
locales
)
{
for
(
const
asset
of
assets
)
{
// _next/static asset
const
res
=
await
fetchViaHTTP
(
ctx
.
appPort
,
`
${
ctx
.
basePath
||
''
}
/
${
locale
}
/_next/static/
${
asset
}
`
,
undefined
,
{
redirect
:
'manual'
}
)
expect
(
res
.
status
).
toBe
(
404
)
expect
(
await
res
.
text
()).
toContain
(
'could not be found'
)
}
}
})
it
(
'should redirect external domain correctly'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
ctx
.
appPort
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment