-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[next]: ensure unmatched action rewrites are routed to correct handler (
#11686) User defined rewrites are "normalized" so that our internal rewrites are still properly handled. Before normalizing these rewrites, the Next.js builder will attempt to match server action requests to a`.action` variant. Then the user-defined rewrites flow through the afterFiles normalization ([this part](https://github.com/vercel/vercel/blob/fix/unmatched-action-rewrites/packages/next/src/server-build.ts#L254-L279)) so that when we add `.action` in the builder, we don't drop the suffix. But this normalization can lead to a malformed `dest`. e.g., if I had rewrite like this: ```js { source: '/greedy-rewrite/static/:path*', destination: '/static/:path*', } ``` The builder would go through this flow on an action request to `/greedy-rewrite/static`: 1. It'll attempt to match it to a `.action` output, so `/greedy-rewrite/static` -> `/greedy-rewrite/static.action` 2. The afterFiles normalization will take place, so the original `dest` of `/static/$1` will become `/static/$1$rscsuff` 3. $1 will be an empty string, because it doesn't match the existing capture group. So now `/greedy-rewrite/static.action` -> `/greedy-rewrite/static/.action` 4. `static/.action` is not a valid output, so it'll 404 and the action will break. Existing handling exists for `.rsc` outputs for a similar reason, but only on the index route. I added a similar fix for this in #11688.
- Loading branch information
Showing
7 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@vercel/next': patch | ||
--- | ||
|
||
ensure unmatched action rewrites are routed to correct handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ages/next/test/fixtures/00-app-dir-actions-experimental-streaming/app/edge/static/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import { increment } from "../../actions"; | ||
|
||
export default function Home() { | ||
const [count, setCount] = useState(0); | ||
|
||
return ( | ||
<div> | ||
{count} | ||
<button | ||
onClick={async () => { | ||
const actionResult = await increment(count); | ||
// @ts-ignore | ||
setCount(actionResult); | ||
console.log(actionResult); | ||
}} | ||
> | ||
Trigger | ||
</button> | ||
Static | ||
</div> | ||
); | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/next/test/fixtures/00-app-dir-actions-experimental-streaming/app/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import { increment } from "./actions"; | ||
|
||
export default function Home() { | ||
const [count, setCount] = useState(0); | ||
|
||
return ( | ||
<div> | ||
{count} | ||
<button | ||
onClick={async () => { | ||
const actionResult = await increment(count); | ||
// @ts-ignore | ||
setCount(actionResult); | ||
console.log(actionResult); | ||
}} | ||
> | ||
Trigger | ||
</button> | ||
Static | ||
</div> | ||
); | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/next/test/fixtures/00-app-dir-actions-experimental-streaming/app/static/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import { increment } from "../actions"; | ||
|
||
export default function Home() { | ||
const [count, setCount] = useState(0); | ||
|
||
return ( | ||
<div> | ||
{count} | ||
<button | ||
onClick={async () => { | ||
const actionResult = await increment(count); | ||
// @ts-ignore | ||
setCount(actionResult); | ||
console.log(actionResult); | ||
}} | ||
> | ||
Trigger | ||
</button> | ||
Static | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters