Skip to content

Commit

Permalink
fix: move the default query client to outside of the component (#437)
Browse files Browse the repository at this point in the history
The current implementation of the query client within the function
component leads to the creation of a new query client on each re-render.
Consequently, this behavior results in the loss of data and caches
associated with the query client.

This PR addresses the issue by relocating the default query client
outside of the function component. By doing so, we ensure that the query
client persists across re-renders, maintaining data integrity and cache
consistency.

While it's possible to resolve this issue by directly providing the
query client to the Provider on usage, this caused us some time to
locate and fix the issue, hence the decision to refactor the
implementation.
  • Loading branch information
fracek authored May 6, 2024
2 parents aed377d + 1ab99de commit ffa854a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/shy-planets-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@starknet-react/core": patch
---

Move the default query client to outside of the Provider component
4 changes: 3 additions & 1 deletion packages/core/src/context/starknet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { ChainProviderFactory } from "~/providers";
import { ExplorerFactory } from "~/explorers/";
import { AccountProvider } from "./account";

const defaultQueryClient = new QueryClient();

/** State of the Starknet context. */
export interface StarknetState {
/** Connected connector. */
Expand Down Expand Up @@ -317,7 +319,7 @@ export function StarknetProvider({
});

return (
<QueryClientProvider client={queryClient ?? new QueryClient()}>
<QueryClientProvider client={queryClient ?? defaultQueryClient}>
<StarknetContext.Provider value={state}>
<AccountProvider account={account}>{children}</AccountProvider>
</StarknetContext.Provider>
Expand Down

0 comments on commit ffa854a

Please sign in to comment.