Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Aug 9, 2024
1 parent 321ca2e commit 5310886
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
6 changes: 2 additions & 4 deletions packages/next/src/server/lib/patch-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ type PatchedFetcher = Fetcher & {
export const NEXT_PATCH_SYMBOL = Symbol.for('next-patch')

function isFetchPatched() {
// @ts-ignore
return globalThis[NEXT_PATCH_SYMBOL] === true
return (globalThis as Record<symbol, unknown>)[NEXT_PATCH_SYMBOL] === true
}

export function validateRevalidate(
Expand Down Expand Up @@ -801,8 +800,7 @@ function createPatchedFetcher(
patched.__nextPatched = true as const
patched.__nextGetStaticStore = () => staticGenerationAsyncStorage
patched._nextOriginalFetch = originFetch
// @ts-ignore
globalThis[NEXT_PATCH_SYMBOL] = true
;(globalThis as Record<symbol, unknown>)[NEXT_PATCH_SYMBOL] = true

return patched
}
Expand Down
5 changes: 2 additions & 3 deletions packages/next/src/server/lib/router-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ export async function initialize(opts: {
require('./router-utils/setup-dev-bundler') as typeof import('./router-utils/setup-dev-bundler')

const resetFetch = () => {
global.fetch = originalFetch
// @ts-ignore
global[NEXT_PATCH_SYMBOL] = false
globalThis.fetch = originalFetch
;(globalThis as Record<symbol, unknown>)[NEXT_PATCH_SYMBOL] = false
}

const setupDevBundlerSpan = opts.startServerSpan
Expand Down
14 changes: 3 additions & 11 deletions test/development/app-dir/dev-fetch-hmr/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,17 @@ import { ReactNode } from 'react'
const magicNumber = Math.random()
const originalFetch = globalThis.fetch

console.log('monkey patching fetch')

// @ts-ignore
globalThis.fetch = async (
resource: URL | RequestInfo,
options?: RequestInit
) => {
let url: string
if (typeof resource === 'string') {
url = resource
} else {
url = resource instanceof URL ? resource.href : resource.url
}
const request = new Request(resource)

if (url === 'http://fake.url/secret') {
if (request.url === 'http://fake.url/secret') {
return new Response('monkey patching is fun')
}

if (url === 'http://fake.url/magic-number') {
if (request.url === 'http://fake.url/magic-number') {
return new Response(magicNumber.toString())
}

Expand Down

0 comments on commit 5310886

Please sign in to comment.