Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.2k
perf: use stable-hash for hashing keys#11073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
94e5360cb1fe5e3e905a99e82aa5208d1c9File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -885,10 +885,9 @@ describe('query', () => { | ||
| const unsubscribe = observer.subscribe(() => undefined) | ||
| await vi.advanceTimersByTimeAsync(10) | ||
| const query = queryCache.find({ queryKey: key })! | ||
| expect(observer.getCurrentResult()).toMatchObject({ | ||
| status: 'error', | ||
| error: new Error(`Missing queryFn: '${query.queryHash}'`), | ||
| error: new Error(`Missing queryFn: '${JSON.stringify(key)}'`), | ||
43081j marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }) | ||
| unsubscribe() | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { tryResolveSync } from './thenable' | ||
| import { noop } from './utils' | ||
| import { describeKey, hashQueryKeyByOptions, noop } from './utils' | ||
| import type { | ||
| DefaultError, | ||
| MutationKey, | ||
| @@ -89,7 +89,7 @@ function dehydrateQuery( | ||
| // If not in production, log original error before rejecting redacted error | ||
| if (process.env.NODE_ENV !== 'production') { | ||
| console.error( | ||
| `A query that was dehydrated as pending ended up rejecting. [${query.queryHash}]: ${error}; The error will be redacted in production builds`, | ||
| `A query that was dehydrated as pending ended up rejecting. [${describeKey(query.queryKey)}]: ${error}; The error will be redacted in production builds`, | ||
| ) | ||
| } | ||
| return Promise.reject(new Error('redacted')) | ||
| @@ -193,6 +193,11 @@ export function hydrate( | ||
| client.getDefaultOptions().hydrate?.deserializeData ?? | ||
| defaultTransformerFn | ||
| const queryDefaults = { | ||
| ...client.getDefaultOptions().hydrate?.queries, | ||
| ...options?.defaultOptions?.queries, | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
| const mutations = (dehydratedState as DehydratedState).mutations || [] | ||
| // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | ||
| @@ -211,15 +216,15 @@ export function hydrate( | ||
| }) | ||
| queries.forEach( | ||
| ({ | ||
| queryKey, | ||
| state, | ||
| queryHash, | ||
| meta, | ||
| promise, | ||
| dehydratedAt, | ||
| queryType, | ||
| }) => { | ||
| ({ queryKey, state, meta, promise, dehydratedAt, queryType }) => { | ||
| // The hash is recomputed rather than read from the payload, so | ||
| // that payloads written by the old hash implementation still resolve | ||
| // to the same cache entry | ||
| const queryHash = hashQueryKeyByOptions( | ||
| queryKey, | ||
| client.defaultQueryOptions({ ...queryDefaults, queryKey }), | ||
| ) | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const syncData = promise ? tryResolveSync(promise) : undefined | ||
| const rawData = state.data === undefined ? syncData?.data : state.data | ||
| const data = rawData === undefined ? rawData : deserializeData(rawData) | ||
| @@ -266,8 +271,7 @@ export function hydrate( | ||
| query = queryCache.build( | ||
| client, | ||
| { | ||
| ...client.getDefaultOptions().hydrate?.queries, | ||
| ...options?.defaultOptions?.queries, | ||
| ...queryDefaults, | ||
| queryKey, | ||
| queryHash, | ||
| meta, | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.