Skip to content

Commit

Permalink
馃悰(frontend) fix infinite loader for product widget
Browse files Browse the repository at this point in the history
This bug was occuring when clicking on the button "Login to purchase"
causing a removal of existing react-query queries. This was caused by
premature removal of the pending useCourse query which was never notified
that it had been removed during its loading, resulting in an infinite
loading state.
  • Loading branch information
NathanVss committed Nov 15, 2022
1 parent 59b715e commit 6655ab7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const JoanieSessionProvider = ({ children }: React.PropsWithChildren<any>) => {
useEffect(() => {
// When user is updated, session queries should be invalidated.
if (previousUserState !== user) {
queryClient.removeQueries({
queryClient.invalidateQueries({
predicate: (query: any) =>
query.options.queryKey.includes('user') && query.options.queryKey.length > 1,
});
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/js/hooks/useCourse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import { useQuery, useQueryClient } from '@tanstack/react-query';
import { useJoanieApi } from 'data/JoanieApiProvider';
import useLocalizedQueryKey from 'utils/react-query/useLocalizedQueryKey';
import { REACT_QUERY_SETTINGS } from 'settings';
import { useSession } from 'data/SessionProvider';
import { REACT_QUERY_SETTINGS } from 'settings';

/**
* Joanie Api hook to retrieve information of a course for the given code.
Expand All @@ -26,7 +26,6 @@ export const useCourse = (code: string) => {
refetch,
isLoading,
} = useQuery(QUERY_KEY, () => API.courses.get(code), {
enabled: user !== undefined,
staleTime: user
? REACT_QUERY_SETTINGS.staleTimes.sessionItems
: REACT_QUERY_SETTINGS.staleTimes.default,
Expand Down

0 comments on commit 6655ab7

Please sign in to comment.