Skip to content

Commit 5310886

Browse files
committed
Address review comments
1 parent 321ca2e commit 5310886

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

packages/next/src/server/lib/patch-fetch.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ type PatchedFetcher = Fetcher & {
3333
export const NEXT_PATCH_SYMBOL = Symbol.for('next-patch')
3434

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

4039
export function validateRevalidate(
@@ -801,8 +800,7 @@ function createPatchedFetcher(
801800
patched.__nextPatched = true as const
802801
patched.__nextGetStaticStore = () => staticGenerationAsyncStorage
803802
patched._nextOriginalFetch = originFetch
804-
// @ts-ignore
805-
globalThis[NEXT_PATCH_SYMBOL] = true
803+
;(globalThis as Record<symbol, unknown>)[NEXT_PATCH_SYMBOL] = true
806804

807805
return patched
808806
}

packages/next/src/server/lib/router-server.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ export async function initialize(opts: {
127127
require('./router-utils/setup-dev-bundler') as typeof import('./router-utils/setup-dev-bundler')
128128

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

135134
const setupDevBundlerSpan = opts.startServerSpan

test/development/app-dir/dev-fetch-hmr/app/layout.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,17 @@ import { ReactNode } from 'react'
44
const magicNumber = Math.random()
55
const originalFetch = globalThis.fetch
66

7-
console.log('monkey patching fetch')
8-
9-
// @ts-ignore
107
globalThis.fetch = async (
118
resource: URL | RequestInfo,
129
options?: RequestInit
1310
) => {
14-
let url: string
15-
if (typeof resource === 'string') {
16-
url = resource
17-
} else {
18-
url = resource instanceof URL ? resource.href : resource.url
19-
}
11+
const request = new Request(resource)
2012

21-
if (url === 'http://fake.url/secret') {
13+
if (request.url === 'http://fake.url/secret') {
2214
return new Response('monkey patching is fun')
2315
}
2416

25-
if (url === 'http://fake.url/magic-number') {
17+
if (request.url === 'http://fake.url/magic-number') {
2618
return new Response(magicNumber.toString())
2719
}
2820

0 commit comments

Comments
 (0)