From 000e2c7259406a5762f421f7b20b246f56c0a4ae Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Wed, 2 Nov 2022 23:18:45 +0530 Subject: [PATCH] fix linr --- .../blitz-rpc/src/data-client/react-query.tsx | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/packages/blitz-rpc/src/data-client/react-query.tsx b/packages/blitz-rpc/src/data-client/react-query.tsx index e83640502a..06901c590f 100644 --- a/packages/blitz-rpc/src/data-client/react-query.tsx +++ b/packages/blitz-rpc/src/data-client/react-query.tsx @@ -21,8 +21,8 @@ import { getInfiniteQueryKey, } from "./react-query-utils" import {useRouter} from "next/router" -import { EmptyPublicData, PublicData } from "../resolver" -import { useEffect, useState } from "react" +import {EmptyPublicData, PublicData} from "../resolver" +import {useEffect, useState} from "react" export interface UseSessionOptions { initialPublicData?: PublicData @@ -36,14 +36,6 @@ export interface ClientSession extends EmptyPublicData { } export const useSession = (options: UseSessionOptions = {}, enabled = false): ClientSession => { - - if(enabled === false) { - return { - ...emptyPublicData, - isLoading: false, - } - } - const suspense = options?.suspense ?? Boolean(globalThis.__BLITZ_SUSPENSE_ENABLED) let initialState: ClientSession @@ -66,13 +58,14 @@ export const useSession = (options: UseSessionOptions = {}, enabled = false): Cl useEffect(() => { // Initialize on mount - setSession({...(window as any).__publicDataStore.getData(), isLoading: false}) - const subscription = (window as any).__publicDataStore.observable.subscribe((data:any) => - setSession({...data, isLoading: false}), - ) - globalThis.__BLITZ_AUTH_ENABLED = true - return subscription.unsubscribe - }, []) + if (enabled) { + setSession({...(window as any).__publicDataStore.getData(), isLoading: false}) + const subscription = (window as any).__publicDataStore.observable.subscribe((data: any) => + setSession({...data, isLoading: false}), + ) + return subscription.unsubscribe + } + }, [enabled]) return session } @@ -312,7 +305,7 @@ export function useInfiniteQuery< const session = useSession({suspense}, blitzAuthEnabled) if (session.isLoading) { enabled = false - } + } const routerIsReady = useRouter().isReady || (isServer && suspenseEnabled) const enhancedResolverRpcClient = sanitizeQuery(queryFn)