Skip to content

Commit 5dd7f0d

Browse files
authored
feat(devtools): Make queryclient reactive (#5366)
1 parent 5b53d00 commit 5dd7f0d

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

packages/query-devtools/src/Devtools.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,7 @@ const getStyles = () => {
18441844
background-color: ${colors.darkGray[400]};
18451845
font-size: ${font.size.sm};
18461846
color: ${colors.gray[500]};
1847-
z-index: 2;
1847+
z-index: 7;
18481848
`,
18491849
settingsMenuHeader: css`
18501850
padding: ${tokens.size[1.5]} ${tokens.size[2.5]};

packages/query-devtools/src/index.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type { DevtoolsButtonPosition, DevtoolsPosition, DevToolsErrorType }
1717
export interface TanstackQueryDevtoolsConfig extends QueryDevtoolsProps {}
1818

1919
class TanstackQueryDevtools {
20-
client: QueryClient
20+
client: Signal<QueryClient>
2121
onlineManager: typeof TonlineManager
2222
queryFlavor: string
2323
version: string
@@ -39,7 +39,7 @@ class TanstackQueryDevtools {
3939
initialIsOpen,
4040
errorTypes,
4141
} = config
42-
this.client = client
42+
this.client = createSignal(client)
4343
this.queryFlavor = queryFlavor
4444
this.version = version
4545
this.onlineManager = onlineManager
@@ -65,6 +65,10 @@ class TanstackQueryDevtools {
6565
this.errorTypes[1](errorTypes)
6666
}
6767

68+
setClient(client: QueryClient) {
69+
this.client[1](client)
70+
}
71+
6872
mount<T extends HTMLElement>(el: T) {
6973
if (this.isMounted) {
7074
throw new Error('Devtools is already mounted')
@@ -74,13 +78,16 @@ class TanstackQueryDevtools {
7478
const [pos] = this.position
7579
const [isOpen] = this.initialIsOpen
7680
const [errors] = this.errorTypes
81+
const [queryClient] = this.client
7782
return (
7883
<DevtoolsComponent
79-
client={this.client}
8084
queryFlavor={this.queryFlavor}
8185
version={this.version}
8286
onlineManager={this.onlineManager}
8387
{...{
88+
get client() {
89+
return queryClient()
90+
},
8491
get buttonPosition() {
8592
return btnPosition()
8693
},

packages/react-query-devtools/src/devtools.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ export function ReactQueryDevtools(
4040
props: DevtoolsOptions,
4141
): React.ReactElement | null {
4242
const queryClient = useQueryClient()
43+
const client = props.client || queryClient
4344
const ref = useRef<HTMLDivElement>(null)
4445
const { buttonPosition, position, initialIsOpen, errorTypes } = props
4546
const [devtools] = useState(
4647
new TanstackQueryDevtools({
47-
client: props.client || queryClient,
48+
client: client,
4849
queryFlavor: 'React Query',
4950
version: '5',
5051
onlineManager,
@@ -55,6 +56,10 @@ export function ReactQueryDevtools(
5556
}),
5657
)
5758

59+
useEffect(() => {
60+
devtools.setClient(client)
61+
}, [client, devtools])
62+
5863
useEffect(() => {
5964
if (buttonPosition) {
6065
devtools.setButtonPosition(buttonPosition)

0 commit comments

Comments
 (0)