Skip to content

Commit

Permalink
Lazily init fetch dedupe cache
Browse files Browse the repository at this point in the history
This module may be included in Pages Router where we don't actually dedupe fetch.

Since React.cache is cleared between requests anyway, initialising it when we patch fetch does not mean we cache less.
Unless we re-patch during requests which would probably be a bug anyway.
  • Loading branch information
eps1lon committed Aug 30, 2024
1 parent 91ba10a commit bd9e57a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/next/src/server/lib/dedupe-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
*/
import * as React from 'react'

// eslint-disable-next-line @typescript-eslint/no-unused-vars -- url is the cache key
const getCacheEntries = React.cache((url: string): Array<any> => [])
const simpleCacheKey = '["GET",[],null,"follow",null,null,null,null]' // generateCacheKey(new Request('https://blank'));

function generateCacheKey(request: Request): string {
Expand All @@ -27,6 +25,9 @@ function generateCacheKey(request: Request): string {
}

export function createDedupeFetch(originalFetch: typeof fetch) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- url is the cache key
const getCacheEntries = React.cache((url: string): Array<any> => [])

return function dedupeFetch(
resource: URL | RequestInfo,
options?: RequestInit
Expand Down

0 comments on commit bd9e57a

Please sign in to comment.