Skip to content

Commit

Permalink
Ensure edge runtime doesn't propagate cache on fetch as Cloudflare …
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
timneutkens committed Nov 2, 2022
1 parent 8715fe0 commit aef04a9
Showing 1 changed file with 11 additions and 5 deletions.
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

0 comments on commit aef04a9

Please sign in to comment.