Unverified Commit 076844e5 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure URL can be passed to fetch correctly (#46592

Fixes: 

![CleanShot 2023-02-28 at 22 35
57@2x](https://user-images.githubusercontent.com/22380829/222042856-ee6dc3c4-c143-49f2-8023-5def749d6a64.png)


## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)
parent 5d48d7e6
...@@ -28,7 +28,11 @@ export function patchFetch({ ...@@ -28,7 +28,11 @@ export function patchFetch({
}, },
async (input: RequestInfo | URL, init: RequestInit | undefined) => { async (input: RequestInfo | URL, init: RequestInit | undefined) => {
const staticGenerationStore = staticGenerationAsyncStorage.getStore() const staticGenerationStore = staticGenerationAsyncStorage.getStore()
const isRequestInput = input && typeof input === 'object' const isRequestInput =
input &&
typeof input === 'object' &&
typeof (input as Request).method === 'string'
const getRequestMeta = (field: string) => { const getRequestMeta = (field: string) => {
let value = isRequestInput ? (input as any)[field] : null let value = isRequestInput ? (input as any)[field] : null
return value || (init as any)?.[field] return value || (init as any)?.[field]
......
...@@ -7,10 +7,18 @@ export default async function Page() { ...@@ -7,10 +7,18 @@ export default async function Page() {
}) })
).then((res) => res.text()) ).then((res) => res.text())
const data2 = await fetch(
new URL('https://next-data-api-endpoint.vercel.app/api/random'),
{
method: 'POST',
}
).then((res) => res.text())
return ( return (
<> <>
<p id="page">/variable-revalidate/post-method</p> <p id="page">/variable-revalidate/post-method</p>
<p id="page-data">{data}</p> <p id="page-data">{data}</p>
<p id="page-data2">{data2}</p>
</> </>
) )
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment