Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Electron: Uncaught Error: No QueryClient set, use QueryClientProvider to set one #8

Closed
arstnei0 opened this issue Dec 27, 2022 · 6 comments

Comments

@arstnei0
Copy link

I am developing an app with Electron (using electron-vite). It's always showing this error
Screenshot 2022-12-27 at 2 50 32 PM

Here's the repo: https://github.com/zihan-ch/zhim
tRPC client: https://github.com/zihan-ch/zhim/blob/main/src/renderer/src/lib/trpc.ts
main.ts: https://github.com/zihan-ch/zhim/blob/main/src/renderer/src/main.tsx

When I use solid devtools to inspect the app, the context seems to be all right:
Screenshot 2022-12-27 at 2 57 00 PM

I assume that this is an error inside solid-trpc; it might have done some special processes that make the context disappeared.

ps: The app runs well without solid-trpc (the original trpc client instead).

@OrJDev
Copy link
Owner

OrJDev commented Dec 27, 2022

That's because the proxyclient doesn't require a trpc provider, this one does. Make sure to follow the docs and wrap your app with a trpc provider or use create jd app and it will do it for u

@OrJDev
Copy link
Owner

OrJDev commented Dec 27, 2022

Actually i just noticed you did,
im not sure how electron works ive never used it, but if you try a regular app it should work ofc. I will try using it on electron.

This wouldn't work on ssr btw because solid query doesn't support ssr yet

@OrJDev OrJDev changed the title Uncaught Error: No QueryClient set, use QueryClientProvider to set one Electron: Uncaught Error: No QueryClient set, use QueryClientProvider to set one Dec 27, 2022
@arstnei0
Copy link
Author

It seems that when __useQuery is called, the query client context isn't working. I tried to pass a createContext(ctx.queryClient) at the here and it works! This is not a nice solution but it's working. It looks like this:
Screenshot 2022-12-27 at 4 06 02 PM

  function useQuery<
    TPath extends keyof TQueryValues & string,
    TQueryFnData = TQueryValues[TPath]['output'],
    TData = TQueryValues[TPath]['output'],
  >(
    pathAndInput: () => [
      path: TPath,
      ...args: inferHandlerInput<TQueries[TPath]>,
    ],
    opts?: UseTRPCQueryOptions<
      TPath,
      TQueryValues[TPath]['input'],
      TQueryFnData,
      TData,
      TError
    >,
  ): UseTRPCQueryResult<TData, TError> {
    const ctx = useContext();
    // createEffect(() => console.log("opts", opts?.()));
    if (
      typeof window === 'undefined' &&
      ctx.ssrState() === 'prepass' &&
      opts?.trpc?.ssr !== false &&
      opts?.enabled !== false &&
      !ctx.queryClient.getQueryCache().find(getArrayQueryKey(pathAndInput()))
    ) {
      void ctx.prefetchQuery(pathAndInput(), opts as any);
    }

    const shouldAbortOnUnmount = () =>
      opts?.trpc?.abortOnUnmount ?? ctx?.abortOnUnmount ?? false;
    console.log(defaultContext);
    return __useQuery(
      () => getArrayQueryKey(pathAndInput()),
      queryFunctionContext => {
        const actualOpts = () => ({
          ...opts,
          trpc: {
            ...opts?.trpc,
            ...(shouldAbortOnUnmount()
              ? {signal: queryFunctionContext.signal}
              : {}),
          },
        });
        return (ctx.client as any).query(
          ...getClientArgs(pathAndInput(), actualOpts()),
        );
      },
      {
        ...opts,
        context: createContext(ctx.queryClient),
      } as any,
    ) as UseTRPCQueryResult<TData, TError>;
  }

@arstnei0
Copy link
Author

Maybe it's the internal error of createQuery?

@OrJDev
Copy link
Owner

OrJDev commented Dec 27, 2022

no it should be working fine (if you use create jd app, which will not use electron its workin fine),
how do i repro? i think ik what the issue is

@OrJDev
Copy link
Owner

OrJDev commented Dec 31, 2022

solidjs/vite-plugin-solid#80

TanStack/query#4673

This seems like a solid query issue, will keep you updated (according to Aryan)

Closing this for now

@OrJDev OrJDev closed this as not planned Won't fix, can't repro, duplicate, stale Dec 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants