-
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] Only rewrite next-action requests to
.action
handlers (#11504)
This only rewrites requests that contain a `next-action` header (explicitly indicating it's a server action). A side effect is that POST requests to a server action on a static route, without a next-action header, won't be marked as streaming (but will still execute normally). This is fine as only the handled action needs to stream. This relands .action handling behind a feature flag.
- Loading branch information
Showing
29 changed files
with
664 additions
and
11 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 | ||
--- | ||
|
||
Only rewrite next-action requests to `.action` handlers |
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
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
6 changes: 6 additions & 0 deletions
6
packages/next/test/fixtures/00-app-dir-actions-experimental-streaming/app/actions.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,6 @@ | ||
'use server'; | ||
|
||
export async function increment(value) { | ||
await new Promise(resolve => setTimeout(resolve, 500)); | ||
return value + 1; | ||
} |
19 changes: 19 additions & 0 deletions
19
...t/test/fixtures/00-app-dir-actions-experimental-streaming/app/client/dynamic/[id]/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,19 @@ | ||
'use client'; | ||
|
||
import { useState } from 'react'; | ||
import { increment } from '../../../actions'; | ||
|
||
export default function Page() { | ||
const [count, setCount] = useState(0); | ||
async function updateCount() { | ||
const newCount = await increment(count); | ||
setCount(newCount); | ||
} | ||
|
||
return ( | ||
<form action={updateCount}> | ||
<div id="count">{count}</div> | ||
<button>Submit</button> | ||
</form> | ||
); | ||
} |
5 changes: 5 additions & 0 deletions
5
...next/test/fixtures/00-app-dir-actions-experimental-streaming/app/client/dynamic/layout.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,5 @@ | ||
export const dynamic = 'force-dynamic'; | ||
|
||
export default function Layout({ children }) { | ||
return children; | ||
} |
19 changes: 19 additions & 0 deletions
19
...ures/00-app-dir-actions-experimental-streaming/app/client/static/[dynamic-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,19 @@ | ||
'use client'; | ||
|
||
import { useState } from 'react'; | ||
import { increment } from '../../../actions'; | ||
|
||
export default function Page() { | ||
const [count, setCount] = useState(0); | ||
async function updateCount() { | ||
const newCount = await increment(count); | ||
setCount(newCount); | ||
} | ||
|
||
return ( | ||
<form action={updateCount}> | ||
<div id="count">{count}</div> | ||
<button>Submit</button> | ||
</form> | ||
); | ||
} |
5 changes: 5 additions & 0 deletions
5
.../next/test/fixtures/00-app-dir-actions-experimental-streaming/app/client/static/layout.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,5 @@ | ||
export const dynamic = 'force-static'; | ||
|
||
export default function Layout({ children }) { | ||
return children; | ||
} |
19 changes: 19 additions & 0 deletions
19
...es/next/test/fixtures/00-app-dir-actions-experimental-streaming/app/client/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,19 @@ | ||
'use client'; | ||
|
||
import { useState } from 'react'; | ||
import { increment } from '../../actions'; | ||
|
||
export default function Page() { | ||
const [count, setCount] = useState(0); | ||
async function updateCount() { | ||
const newCount = await increment(count); | ||
setCount(newCount); | ||
} | ||
|
||
return ( | ||
<form action={updateCount}> | ||
<div id="count">{count}</div> | ||
<button>Submit</button> | ||
</form> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/next/test/fixtures/00-app-dir-actions-experimental-streaming/app/layout.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,10 @@ | ||
export default function Root({ children }) { | ||
return ( | ||
<html> | ||
<head> | ||
<title>Hello World</title> | ||
</head> | ||
<body>{children}</body> | ||
</html> | ||
); | ||
} |
45 changes: 45 additions & 0 deletions
45
packages/next/test/fixtures/00-app-dir-actions-experimental-streaming/app/other/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,45 @@ | ||
'use client'; | ||
|
||
// @ts-ignore | ||
import { useCallback, useState } from 'react'; | ||
|
||
function request(method) { | ||
return fetch('/api/test', { | ||
method, | ||
headers: { | ||
'content-type': 'multipart/form-data;.*', | ||
}, | ||
}); | ||
} | ||
|
||
export default function Home() { | ||
const [result, setResult] = useState('Press submit'); | ||
const onClick = useCallback(async method => { | ||
const res = await request(method); | ||
const text = await res.text(); | ||
|
||
setResult(res.ok ? `${method} ${text}` : 'Error: ' + res.status); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<div className="flex flex-col items-center justify-center h-screen"> | ||
<div className="flex flex-row space-x-2 items-center justify-center"> | ||
<button | ||
className="border border-white rounded-sm p-4 mb-4" | ||
onClick={() => onClick('GET')} | ||
> | ||
Submit GET | ||
</button> | ||
<button | ||
className="border border-white rounded-sm p-4 mb-4" | ||
onClick={() => onClick('POST')} | ||
> | ||
Submit POST | ||
</button> | ||
</div> | ||
<div className="text-white">{result}</div> | ||
</div> | ||
</> | ||
); | ||
} |
5 changes: 5 additions & 0 deletions
5
...es/next/test/fixtures/00-app-dir-actions-experimental-streaming/app/rsc/dynamic/layout.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,5 @@ | ||
export const dynamic = 'force-dynamic'; | ||
|
||
export default function Layout({ children }) { | ||
return children; | ||
} |
15 changes: 15 additions & 0 deletions
15
...ages/next/test/fixtures/00-app-dir-actions-experimental-streaming/app/rsc/dynamic/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,15 @@ | ||
import { revalidatePath } from 'next/cache'; | ||
|
||
export default async function Page() { | ||
async function serverAction() { | ||
'use server'; | ||
await new Promise(resolve => setTimeout(resolve, 1000)); | ||
revalidatePath('/dynamic'); | ||
} | ||
|
||
return ( | ||
<form action={serverAction}> | ||
<button>Submit</button> | ||
</form> | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
...ixtures/00-app-dir-actions-experimental-streaming/app/rsc/static/[dynamic-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,15 @@ | ||
import { revalidatePath } from 'next/cache'; | ||
|
||
export default async function Page() { | ||
async function serverAction() { | ||
'use server'; | ||
await new Promise(resolve => setTimeout(resolve, 1000)); | ||
revalidatePath('/dynamic'); | ||
} | ||
|
||
return ( | ||
<form action={serverAction}> | ||
<button>Submit</button> | ||
</form> | ||
); | ||
} |
Oops, something went wrong.