-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suspense cache: use Trie directly (#10969)
Co-authored-by: Jerel Miller <jerelmiller@gmail.com>
- Loading branch information
1 parent
e187866
commit 525a931
Showing
7 changed files
with
118 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@apollo/client': patch | ||
--- | ||
|
||
Slightly decrease bundle size and memory footprint of `SuspenseCache` by changing how cache entries are stored internally. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { expect } from '@jest/globals'; | ||
import { toMatchDocument } from './toMatchDocument'; | ||
import { toHaveSuspenseCacheEntryUsing } from './toHaveSuspenseCacheEntryUsing'; | ||
|
||
expect.extend({ | ||
toHaveSuspenseCacheEntryUsing, | ||
toMatchDocument, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { MatcherFunction } from 'expect'; | ||
import type { DocumentNode } from 'graphql'; | ||
import type { ApolloClient, OperationVariables } from '../../core'; | ||
import { SuspenseCache } from '../../react'; | ||
import { canonicalStringify } from '../../cache'; | ||
|
||
export const toHaveSuspenseCacheEntryUsing: MatcherFunction< | ||
[ | ||
client: ApolloClient<unknown>, | ||
query: DocumentNode, | ||
options: { | ||
variables?: OperationVariables; | ||
queryKey?: string | number | any[]; | ||
} | ||
] | ||
> = function ( | ||
suspenseCache, | ||
client, | ||
query, | ||
{ variables, queryKey = [] } = Object.create(null) | ||
) { | ||
if (!(suspenseCache instanceof SuspenseCache)) { | ||
throw new Error('Actual must be an instance of `SuspenseCache`'); | ||
} | ||
|
||
const cacheKey = ( | ||
[client, query, canonicalStringify(variables)] as any[] | ||
).concat(queryKey); | ||
const queryRef = suspenseCache['queryRefs'].lookupArray(cacheKey)?.current; | ||
|
||
return { | ||
pass: !!queryRef, | ||
message: () => { | ||
return `Expected suspense cache ${ | ||
queryRef ? 'not ' : '' | ||
}to have cache entry using key`; | ||
}, | ||
}; | ||
}; |