Skip to content

Commit 13daae9

Browse files
Merge 5c7ac1a into 2404071
2 parents 2404071 + 5c7ac1a commit 13daae9

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

package-lock.json

Lines changed: 13 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"semver": "7.5.4",
8585
"sharp": "0.32.1",
8686
"svg-points": "6.0.1",
87-
"swr": "1.3.0",
87+
"swr": "2.2.0",
8888
"tailwindcss": "3.1.8",
8989
"url-loader": "4.1.1",
9090
"uuid-parse": "1.1.0",

pages/appeals/[id].js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default function Page () {
7777
const canComment = appeal.state.id < 3 && appeal.acl.comment
7878
const canUpdateState = appeal.acl.state
7979
const canAssign = appeal.acl.assign
80-
const mutateCommentInsert = (comment) => (data, mutate) => {
80+
const mutateCommentInsert = (comment) => ({ data }, mutate) => {
8181
const records = data.listPlayerAppealComments.records.slice()
8282

8383
records.push(comment)

utils/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ const graphQLClient = new GraphQLClient(process.env.BASE_PATH + '/graphql', {
3737
credentials: 'include'
3838
})
3939

40-
const graphqlFetcher = (query, ...args) => {
40+
const graphqlFetcher = (key) => {
41+
const [query, ...args] = key
4142
// Creates an object. Odd indexes are keys and even indexes are values.
4243
// Needs to be flat to avoid unnecessary rerendering since swr does shallow comparison.
4344
const variables = [...(args || [])].reduce((acc, arg, index, arr) => {
@@ -66,7 +67,7 @@ export const useMutateApi = (operation) => {
6667
setLoading(true)
6768

6869
try {
69-
const data = await graphqlFetcher(operation.query, ...flatVars)
70+
const data = await graphqlFetcher([operation.query, ...flatVars])
7071

7172
setState({ ...state, errors: null, data })
7273
} catch (error) {
@@ -87,20 +88,17 @@ export const useMatchMutate = () => {
8788
throw new Error('matchMutate requires the cache provider to be a Map instance')
8889
}
8990

90-
const flatVars = toPairs(args).flat()
91-
const argKey = unstableSerialize(flatVars).slice(1)
92-
9391
let matchingKey
9492

9593
for (const key of cache.keys()) {
9694
if (key.includes(operation)) {
9795
const value = cache.get(key)
9896

99-
if (!value || !value[operation]) {
97+
if (!value) {
10098
continue
10199
}
102100

103-
if (!argKey || key.includes(argKey)) {
101+
if (key === unstableSerialize(value._k)) {
104102
matchingKey = key
105103
break
106104
}
@@ -110,7 +108,7 @@ export const useMatchMutate = () => {
110108
if (!matchingKey) return () => {}
111109

112110
return executor(cache.get(matchingKey), (...args) => {
113-
mutate(matchingKey, ...args)
111+
mutate(matchingKey, args[0])
114112
})
115113
}
116114
}

0 commit comments

Comments
 (0)