Skip to content

Commit

Permalink
fix: Improve comparison performance (vercel#2973)
Browse files Browse the repository at this point in the history
use deep comparison instead of hashing the fetch body
  • Loading branch information
shuding authored and kimdaeyeub committed Jun 20, 2024
1 parent 3f98283 commit 76b18db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"trailingComma": "none"
},
"dependencies": {
"dequal": "^2.0.3",
"use-sync-external-store": "^1.2.0"
}
}
16 changes: 12 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/_internal/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import type {
ScopedMutator,
Cache
} from '../types'
import { stableHash } from './hash'

import { initCache } from './cache'
import { preset } from './web-preset'
import { slowConnection } from './env'
import { isUndefined, noop, mergeObjects } from './shared'

import { dequal } from 'dequal/lite'

// error retry
const onErrorRetry = (
_: unknown,
Expand All @@ -37,8 +39,7 @@ const onErrorRetry = (
setTimeout(revalidate, timeout, opts)
}

const compare = (currentData: any, newData: any) =>
stableHash(currentData) == stableHash(newData)
const compare = dequal

// Default cache provider
const [cache, mutate] = initCache(new Map()) as [Cache<any>, ScopedMutator]
Expand Down

0 comments on commit 76b18db

Please sign in to comment.