Unverified Commit aef04a98 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Ensure edge runtime doesn't propagate `cache` on fetch as Cloudflare doesn't support it. (#42362)

Ensures `cache` property is removed. We'll want to move this handling
into the `edge-runtime` package though.


<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent 8715fe03
...@@ -39,6 +39,8 @@ import { HeadManagerContext } from '../shared/lib/head-manager-context' ...@@ -39,6 +39,8 @@ import { HeadManagerContext } from '../shared/lib/head-manager-context'
import { Writable } from 'stream' import { Writable } from 'stream'
import stringHash from 'next/dist/compiled/string-hash' import stringHash from 'next/dist/compiled/string-hash'
const isEdgeRuntime = process.env.NEXT_RUNTIME === 'edge'
function preloadComponent(Component: any, props: any) { function preloadComponent(Component: any, props: any) {
const prev = console.error const prev = console.error
// Hide invalid hook call warning when calling component // Hide invalid hook call warning when calling component
...@@ -238,7 +240,12 @@ function patchFetch(ComponentMod: any) { ...@@ -238,7 +240,12 @@ function patchFetch(ComponentMod: any) {
if (staticGenerationStore && isStaticGeneration) { if (staticGenerationStore && isStaticGeneration) {
if (init && typeof init === 'object') { if (init && typeof init === 'object') {
if (init.cache === 'no-store') { const cache = init.cache
// Delete `cache` property as Cloudflare Workers will throw an error
if (isEdgeRuntime) {
delete init.cache
}
if (cache === 'no-store') {
staticGenerationStore.fetchRevalidate = 0 staticGenerationStore.fetchRevalidate = 0
// TODO: ensure this error isn't logged to the user // TODO: ensure this error isn't logged to the user
// seems it's slipping through currently // seems it's slipping through currently
...@@ -296,10 +303,9 @@ function useFlightResponse( ...@@ -296,10 +303,9 @@ function useFlightResponse(
const [renderStream, forwardStream] = readableStreamTee(req) const [renderStream, forwardStream] = readableStreamTee(req)
const res = createFromReadableStream(renderStream, { const res = createFromReadableStream(renderStream, {
moduleMap: moduleMap: isEdgeRuntime
process.env.NEXT_RUNTIME === 'edge' ? serverComponentManifest.__edge_ssr_module_mapping__
? serverComponentManifest.__edge_ssr_module_mapping__ : serverComponentManifest.__ssr_module_mapping__,
: serverComponentManifest.__ssr_module_mapping__,
}) })
flightResponseRef.current = res flightResponseRef.current = res
......
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