From abcef4a50269bbfc751a9578f476941b016874db Mon Sep 17 00:00:00 2001 From: Muhammad Waleed <81019006+Waleed-Mujahid@users.noreply.github.com> Date: Thu, 5 Mar 2026 14:17:27 +0500 Subject: [PATCH] fix: refresh search token after library (#2924) creation for course creator access When a course creator creates a new library, the cached JWT token for Meilisearch needs to be refreshed to include the new library's access_id. Without this, newly added components won't appear in search results until the page is refreshed. This works in conjunction with the backend fix that creates SearchAccess records immediately on library creation. The fix invalidates the content_search query, triggering React Query to refetch the token with updated access permissions. --- src/library-authoring/create-library/data/apiHooks.test.tsx | 3 +++ src/library-authoring/create-library/data/apiHooks.ts | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/library-authoring/create-library/data/apiHooks.test.tsx b/src/library-authoring/create-library/data/apiHooks.test.tsx index 0075bcac6..726cbee02 100644 --- a/src/library-authoring/create-library/data/apiHooks.test.tsx +++ b/src/library-authoring/create-library/data/apiHooks.test.tsx @@ -63,6 +63,9 @@ describe('create library apiHooks', () => { expect(invalidateQueriesSpy).toHaveBeenCalledWith({ queryKey: libraryAuthoringQueryKeys.contentLibraryList(), }); + expect(invalidateQueriesSpy).toHaveBeenCalledWith({ + queryKey: ['content_search'], + }); }); }); diff --git a/src/library-authoring/create-library/data/apiHooks.ts b/src/library-authoring/create-library/data/apiHooks.ts index 1f5371968..1a5880a5d 100644 --- a/src/library-authoring/create-library/data/apiHooks.ts +++ b/src/library-authoring/create-library/data/apiHooks.ts @@ -23,6 +23,8 @@ export const useCreateLibraryV2 = () => { mutationFn: createLibraryV2, onSettled: () => { queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.contentLibraryList() }); + // Invalidate the search token to refresh with the new library's access_id + queryClient.invalidateQueries({ queryKey: ['content_search'] }); }, }); };