mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +00:00
fix(nux3): use murmurhash for fetchKey (#1195)
This commit is contained in:
parent
80883cfb8f
commit
4cff21005f
@ -34,6 +34,7 @@
|
||||
"hookable": "^5.0.0",
|
||||
"ignore": "^5.1.8",
|
||||
"mlly": "^0.2.10",
|
||||
"murmurhash-es": "^0.1.1",
|
||||
"nuxi": "3.0.0",
|
||||
"ohmyfetch": "^0.3.1",
|
||||
"pathe": "^0.2.0",
|
||||
|
@ -1,5 +1,6 @@
|
||||
import type { FetchOptions } from 'ohmyfetch'
|
||||
import type { $Fetch } from '@nuxt/nitro'
|
||||
import { murmurHashV3 } from 'murmurhash-es'
|
||||
import type { AsyncDataOptions, _Transform, KeyOfRes } from './asyncData'
|
||||
import { useAsyncData } from './asyncData'
|
||||
|
||||
@ -35,10 +36,9 @@ export function useFetch<
|
||||
opts.key = generateKey(keys)
|
||||
}
|
||||
|
||||
return useAsyncData('$f' + opts.key, () => $fetch(url, opts) as Promise<ResT>, opts)
|
||||
return useAsyncData(opts.key, () => $fetch(url, opts) as Promise<ResT>, opts)
|
||||
}
|
||||
|
||||
// TODO: More predictable universal hash
|
||||
function generateKey (keys) {
|
||||
return JSON.stringify(keys).replace(/[{":}=/,]|https?:\/\//g, '_').replace(/_+/g, '_')
|
||||
return '$f' + murmurHashV3(JSON.stringify(keys))
|
||||
}
|
||||
|
@ -13086,6 +13086,13 @@ fsevents@~2.3.2:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"murmurhash-es@npm:^0.1.1":
|
||||
version: 0.1.1
|
||||
resolution: "murmurhash-es@npm:0.1.1"
|
||||
checksum: 3f5aa267161b21ad5b52f4b240ecd40014f21256114fad4b196202a8079ab08af8cdf5e7136caa591846232edc4222ba790ce300b8a6de6085e68e229da26766
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"mustache@npm:^2.3.0":
|
||||
version: 2.3.2
|
||||
resolution: "mustache@npm:2.3.2"
|
||||
@ -13815,6 +13822,7 @@ fsevents@~2.3.2:
|
||||
hookable: ^5.0.0
|
||||
ignore: ^5.1.8
|
||||
mlly: ^0.2.10
|
||||
murmurhash-es: ^0.1.1
|
||||
nuxi: 3.0.0
|
||||
ohmyfetch: ^0.3.1
|
||||
pathe: ^0.2.0
|
||||
|
Loading…
Reference in New Issue
Block a user