From f99f34c56f4e73db04816668a375a319d0859b4f Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Wed, 20 Jul 2022 22:50:31 +0700 Subject: Fix feature cache across ajaxed page loads (#5841) --- source/github-helpers/api.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'source/github-helpers/api.ts') diff --git a/source/github-helpers/api.ts b/source/github-helpers/api.ts index 13f56f58..4bc0e249 100644 --- a/source/github-helpers/api.ts +++ b/source/github-helpers/api.ts @@ -207,7 +207,17 @@ export const v4 = mem(async ( throw await getError(apiResponse as JsonObject); }, { - cacheKey: JSON.stringify, + cacheKey([query, options]) { + // `repository()` uses global state and must be handled explicitly + // https://github.com/refined-github/refined-github/issues/5821 + // https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1864 + const key = [query, options]; + if (query.includes('repository() {')) { + key.push(getRepo()?.nameWithOwner); + } + + return JSON.stringify(key); + }, }); export async function getError(apiResponse: JsonObject): Promise { -- cgit v1.2.3