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
a154c157
Unverified
Commit
a154c157
authored
Jul 29, 2022
by
JJ Kasper
Committed by
GitHub
Jul 29, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix middleware + afterFiles SSG rewrite case (#39153)
parent
c567d7d2
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
15 deletions
+50
-15
router.ts
packages/next/shared/lib/router/router.ts
+22
-15
next.config.js
test/e2e/middleware-rewrites/app/next.config.js
+4
-0
index.test.ts
test/e2e/middleware-rewrites/test/index.test.ts
+24
-0
No files found.
packages/next/shared/lib/router/router.ts
View file @
a154c157
...
@@ -1747,7 +1747,10 @@ export default class Router implements BaseRouter {
...
@@ -1747,7 +1747,10 @@ export default class Router implements BaseRouter {
route
=
removeTrailingSlash
(
data
.
effect
.
resolvedHref
)
route
=
removeTrailingSlash
(
data
.
effect
.
resolvedHref
)
pathname
=
data
.
effect
.
resolvedHref
pathname
=
data
.
effect
.
resolvedHref
query
=
{
...
query
,
...
data
.
effect
.
parsedAs
.
query
}
query
=
{
...
query
,
...
data
.
effect
.
parsedAs
.
query
}
resolvedAs
=
data
.
effect
.
parsedAs
.
pathname
resolvedAs
=
removeBasePath
(
normalizeLocalePath
(
data
.
effect
.
parsedAs
.
pathname
,
this
.
locales
)
.
pathname
)
// Check again the cache with the new destination.
// Check again the cache with the new destination.
existingInfo
=
this
.
components
[
route
]
existingInfo
=
this
.
components
[
route
]
...
@@ -1806,8 +1809,12 @@ export default class Router implements BaseRouter {
...
@@ -1806,8 +1809,12 @@ export default class Router implements BaseRouter {
const
{
props
}
=
await
this
.
_getData
(
async
()
=>
{
const
{
props
}
=
await
this
.
_getData
(
async
()
=>
{
if
(
shouldFetchData
&&
!
useStreamedFlightData
)
{
if
(
shouldFetchData
&&
!
useStreamedFlightData
)
{
const
{
json
}
=
const
{
json
}
=
data
||
data
?.
json
&&
(
await
fetchNextData
({
data
?.
response
.
headers
.
get
(
'content-type'
)
?.
includes
(
'application/json'
)
?
data
:
await
fetchNextData
({
dataHref
:
this
.
pageLoader
.
getDataHref
({
dataHref
:
this
.
pageLoader
.
getDataHref
({
href
:
formatWithValidation
({
pathname
,
query
}),
href
:
formatWithValidation
({
pathname
,
query
}),
asPath
:
resolvedAs
,
asPath
:
resolvedAs
,
...
@@ -1819,7 +1826,7 @@ export default class Router implements BaseRouter {
...
@@ -1819,7 +1826,7 @@ export default class Router implements BaseRouter {
persistCache
:
!
isPreview
,
persistCache
:
!
isPreview
,
isPrefetch
:
false
,
isPrefetch
:
false
,
unstable_skipClientCache
,
unstable_skipClientCache
,
})
)
}
)
return
{
return
{
props
:
json
,
props
:
json
,
...
...
test/e2e/middleware-rewrites/app/next.config.js
View file @
a154c157
...
@@ -16,6 +16,10 @@ module.exports = {
...
@@ -16,6 +16,10 @@ module.exports = {
source
:
'/afterfiles-rewrite'
,
source
:
'/afterfiles-rewrite'
,
destination
:
'/ab-test/b'
,
destination
:
'/ab-test/b'
,
},
},
{
source
:
'/afterfiles-rewrite-ssg'
,
destination
:
'/fallback-true-blog/first'
,
},
],
],
fallback
:
[],
fallback
:
[],
}
}
...
...
test/e2e/middleware-rewrites/test/index.test.ts
View file @
a154c157
...
@@ -27,6 +27,30 @@ describe('Middleware Rewrite', () => {
...
@@ -27,6 +27,30 @@ describe('Middleware Rewrite', () => {
testsWithLocale
(
'/fr'
)
testsWithLocale
(
'/fr'
)
function
tests
()
{
function
tests
()
{
it
(
'should have props for afterFiles rewrite to SSG page'
,
async
()
=>
{
let
browser
=
await
webdriver
(
next
.
url
,
'/'
)
await
browser
.
eval
(
`next.router.push("/afterfiles-rewrite-ssg")`
)
await
check
(
()
=>
browser
.
eval
(
'next.router.isReady ? "yup": "nope"'
),
'yup'
)
await
check
(
()
=>
browser
.
eval
(
'document.documentElement.innerHTML'
),
/"slug":"first"/
)
browser
=
await
webdriver
(
next
.
url
,
'/afterfiles-rewrite-ssg'
)
await
check
(
()
=>
browser
.
eval
(
'next.router.isReady ? "yup": "nope"'
),
'yup'
)
await
check
(
()
=>
browser
.
eval
(
'document.documentElement.innerHTML'
),
/"slug":"first"/
)
})
it
(
'should hard navigate on 404 for data request'
,
async
()
=>
{
it
(
'should hard navigate on 404 for data request'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/'
)
const
browser
=
await
webdriver
(
next
.
url
,
'/'
)
await
browser
.
eval
(
'window.beforeNav = 1'
)
await
browser
.
eval
(
'window.beforeNav = 1'
)
...
...
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