Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Nov 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions packages/next/server/app-render.tsx
Expand Up @@ -39,6 +39,8 @@ import { HeadManagerContext } from '../shared/lib/head-manager-context'
import { Writable } from 'stream'
import stringHash from 'next/dist/compiled/string-hash'

const isEdgeRuntime = process.env.NEXT_RUNTIME === 'edge'

function preloadComponent(Component: any, props: any) {
const prev = console.error
// Hide invalid hook call warning when calling component
Expand Down Expand Up @@ -238,7 +240,12 @@ function patchFetch(ComponentMod: any) {

if (staticGenerationStore && isStaticGeneration) {
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
// TODO: ensure this error isn't logged to the user
// seems it's slipping through currently
Expand Down Expand Up @@ -296,10 +303,9 @@ function useFlightResponse(

const [renderStream, forwardStream] = readableStreamTee(req)
const res = createFromReadableStream(renderStream, {
moduleMap:
process.env.NEXT_RUNTIME === 'edge'
? serverComponentManifest.__edge_ssr_module_mapping__
: serverComponentManifest.__ssr_module_mapping__,
moduleMap: isEdgeRuntime
? serverComponentManifest.__edge_ssr_module_mapping__
: serverComponentManifest.__ssr_module_mapping__,
})
flightResponseRef.current = res

Expand Down