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
824a0c13
Unverified
Commit
824a0c13
authored
Apr 09, 2025
by
Jiachi Liu
Committed by
GitHub
Apr 09, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[next-server] preserve rsc query for rsc redirects (#77963)
parent
5f480670
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
131 additions
and
3 deletions
+131
-3
prepare-destination.ts
...s/next/src/shared/lib/router/utils/prepare-destination.ts
+0
-3
layout.tsx
test/e2e/app-dir/rsc-query-routing/app/layout.tsx
+8
-0
page.tsx
.../e2e/app-dir/rsc-query-routing/app/redirect/dest/page.tsx
+7
-0
page.tsx
test/e2e/app-dir/rsc-query-routing/app/redirect/page.tsx
+14
-0
page.tsx
test/e2e/app-dir/rsc-query-routing/app/rewrite/dest/page.tsx
+7
-0
page.tsx
test/e2e/app-dir/rsc-query-routing/app/rewrite/page.tsx
+14
-0
next.config.js
test/e2e/app-dir/rsc-query-routing/next.config.js
+25
-0
rsc-query-routing.test.ts
test/e2e/app-dir/rsc-query-routing/rsc-query-routing.test.ts
+56
-0
No files found.
packages/next/src/shared/lib/router/utils/prepare-destination.ts
View file @
824a0c13
...
@@ -11,7 +11,6 @@ import {
...
@@ -11,7 +11,6 @@ import {
INTERCEPTION_ROUTE_MARKERS
,
INTERCEPTION_ROUTE_MARKERS
,
isInterceptionRouteAppPath
,
isInterceptionRouteAppPath
,
}
from
'./interception-routes'
}
from
'./interception-routes'
import
{
NEXT_RSC_UNION_QUERY
}
from
'../../../../client/components/app-router-headers'
import
{
getCookieParser
}
from
'../../../../server/api-utils/get-cookie-parser'
import
{
getCookieParser
}
from
'../../../../server/api-utils/get-cookie-parser'
import
type
{
Params
}
from
'../../../../server/request/params'
import
type
{
Params
}
from
'../../../../server/request/params'
...
@@ -210,8 +209,6 @@ export function prepareDestination(args: {
...
@@ -210,8 +209,6 @@ export function prepareDestination(args: {
query
:
NextParsedUrlQuery
query
:
NextParsedUrlQuery
})
{
})
{
const
query
=
Object
.
assign
({},
args
.
query
)
const
query
=
Object
.
assign
({},
args
.
query
)
delete
query
[
NEXT_RSC_UNION_QUERY
]
const
parsedDestination
=
parseDestination
(
args
)
const
parsedDestination
=
parseDestination
(
args
)
const
{
hostname
:
destHostname
,
query
:
destQuery
}
=
parsedDestination
const
{
hostname
:
destHostname
,
query
:
destQuery
}
=
parsedDestination
...
...
test/e2e/app-dir/rsc-query-routing/app/layout.tsx
0 → 100644
View file @
824a0c13
import
{
ReactNode
}
from
'react'
export
default
function
Root
({
children
}:
{
children
:
ReactNode
})
{
return
(
<
html
>
<
body
>
{
children
}
</
body
>
</
html
>
)
}
test/e2e/app-dir/rsc-query-routing/app/redirect/dest/page.tsx
0 → 100644
View file @
824a0c13
export
default
function
Page
()
{
return
(
<
div
>
<
h1
>
Redirect Dest
</
h1
>
</
div
>
)
}
test/e2e/app-dir/rsc-query-routing/app/redirect/page.tsx
0 → 100644
View file @
824a0c13
import
Link
from
'next/link'
export
default
function
Home
()
{
return
(
<
div
>
{
/* disable prefetch to align the dev/prod fetching behavior,
it's easier for writing tests */
}
Go to
{
' '
}
<
Link
prefetch=
{
false
}
href=
"/redirect/source"
>
Redirect Link
</
Link
>
</
div
>
)
}
test/e2e/app-dir/rsc-query-routing/app/rewrite/dest/page.tsx
0 → 100644
View file @
824a0c13
export
default
function
Page
()
{
return
(
<
div
>
<
h1
>
Rewrite Dest
</
h1
>
</
div
>
)
}
test/e2e/app-dir/rsc-query-routing/app/rewrite/page.tsx
0 → 100644
View file @
824a0c13
import
Link
from
'next/link'
export
default
function
Home
()
{
return
(
<
div
>
{
/* disable prefetch to align the dev/prod fetching behavior,
it's easier for writing tests */
}
Go to
{
' '
}
<
Link
prefetch=
{
false
}
href=
"/rewrite/source"
>
Rewrite Link
</
Link
>
</
div
>
)
}
test/e2e/app-dir/rsc-query-routing/next.config.js
0 → 100644
View file @
824a0c13
/**
* @type {import('next').NextConfig}
*/
const
nextConfig
=
{
reactStrictMode
:
true
,
async
redirects
()
{
return
[
{
source
:
'/redirect/source'
,
destination
:
'/redirect/dest'
,
permanent
:
true
,
},
]
},
async
rewrites
()
{
return
[
{
source
:
'/rewrite/source'
,
destination
:
'/rewrite/dest'
,
},
]
},
}
module
.
exports
=
nextConfig
test/e2e/app-dir/rsc-query-routing/rsc-query-routing.test.ts
0 → 100644
View file @
824a0c13
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
retry
}
from
'next-test-utils'
import
{
Request
}
from
'playwright'
describe
(
'rsc-query-routing'
,
()
=>
{
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
,
})
it
(
'should contain rsc query in rsc request when redirect the page'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/redirect'
)
const
rscRequestUrls
:
string
[]
=
[]
browser
.
on
(
'request'
,
(
req
:
Request
)
=>
{
if
(
req
.
url
().
includes
(
'?_rsc='
))
{
rscRequestUrls
.
push
(
req
.
url
())
}
})
// Click redirect link
const
link
=
await
browser
.
elementByCss
(
'a'
)
await
link
.
click
()
// Wait for the page load to be completed
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'Redirect Dest'
)
})
// The redirect source and dest urls should both contain the rsc query
expect
(
rscRequestUrls
[
0
]).
toContain
(
'/redirect/source'
)
expect
(
rscRequestUrls
[
1
]).
toContain
(
'/redirect/dest'
)
})
it
(
'should contain rsc query in rsc request when rewrite the page'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/rewrite'
)
const
rscRequestUrls
:
string
[]
=
[]
browser
.
on
(
'request'
,
(
req
:
Request
)
=>
{
if
(
req
.
url
().
includes
(
'?_rsc='
))
{
rscRequestUrls
.
push
(
req
.
url
())
}
})
// Click redirect link
const
link
=
await
browser
.
elementByCss
(
'a'
)
await
link
.
click
()
// Wait for the page load to be completed
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'Rewrite Dest'
)
})
// The rewrite source url should contain the rsc query
expect
(
rscRequestUrls
[
0
]).
toContain
(
'/rewrite/source'
)
})
})
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