@tanstack/react-query-devtools 4.14.6 → 4.14.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-query-devtools",
3
- "version": "4.14.6",
3
+ "version": "4.14.8",
4
4
  "description": "Developer tools to interact with and visualize the TanStack/react-query cache",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -4,7 +4,7 @@ import { ErrorBoundary } from 'react-error-boundary'
4
4
  import '@testing-library/jest-dom'
5
5
  import type { QueryClient } from '@tanstack/react-query'
6
6
  import { useQuery } from '@tanstack/react-query'
7
- import { sortFns } from '../utils'
7
+ import { defaultPanelSize, sortFns } from '../utils'
8
8
  import {
9
9
  getByTextContent,
10
10
  renderWithClient,
@@ -36,6 +36,7 @@ Object.defineProperty(window, 'matchMedia', {
36
36
  describe('ReactQueryDevtools', () => {
37
37
  beforeEach(() => {
38
38
  localStorage.removeItem('reactQueryDevtoolsOpen')
39
+ localStorage.removeItem('reactQueryDevtoolsPanelPosition')
39
40
  })
40
41
  it('should be able to open and close devtools', async () => {
41
42
  const { queryClient } = createQueryClient()
@@ -863,4 +864,55 @@ describe('ReactQueryDevtools', () => {
863
864
  expect(panel.style.width).toBe('500px')
864
865
  expect(panel.style.height).toBe('100vh')
865
866
  })
867
+
868
+ it('should restore parent element padding after closing', async () => {
869
+ const { queryClient } = createQueryClient()
870
+
871
+ function Page() {
872
+ const { data = 'default' } = useQuery(['check'], async () => 'test')
873
+
874
+ return (
875
+ <div>
876
+ <h1>{data}</h1>
877
+ </div>
878
+ )
879
+ }
880
+
881
+ const parentElementTestid = 'parentElement'
882
+ const parentPaddings = {
883
+ paddingTop: '428px',
884
+ paddingBottom: '39px',
885
+ paddingLeft: '-373px',
886
+ paddingRight: '20%',
887
+ }
888
+
889
+ function Parent({ children }: { children: React.ReactElement }) {
890
+ return (
891
+ <div data-testid={parentElementTestid} style={parentPaddings}>
892
+ {children}
893
+ </div>
894
+ )
895
+ }
896
+
897
+ renderWithClient(
898
+ queryClient,
899
+ <Page />,
900
+ {
901
+ initialIsOpen: true,
902
+ panelPosition: 'bottom',
903
+ },
904
+ { wrapper: Parent },
905
+ )
906
+
907
+ const parentElement = screen.getByTestId(parentElementTestid)
908
+ expect(parentElement).toHaveStyle({
909
+ paddingTop: '0px',
910
+ paddingLeft: '0px',
911
+ paddingRight: '0px',
912
+ paddingBottom: defaultPanelSize,
913
+ })
914
+
915
+ fireEvent.click(screen.getByRole('button', { name: /^close$/i }))
916
+ expect(parentElement).toHaveStyle(parentPaddings)
917
+ })
866
918
  })
@@ -1,4 +1,4 @@
1
- import { render } from '@testing-library/react'
1
+ import { render, type RenderOptions } from '@testing-library/react'
2
2
  import * as React from 'react'
3
3
  import { ReactQueryDevtools } from '../devtools'
4
4
 
@@ -12,12 +12,14 @@ export function renderWithClient(
12
12
  client: QueryClient,
13
13
  ui: React.ReactElement,
14
14
  devtoolsOptions: Parameters<typeof ReactQueryDevtools>[number] = {},
15
+ renderOptions?: RenderOptions,
15
16
  ): ReturnType<typeof render> {
16
17
  const { rerender, ...result } = render(
17
18
  <QueryClientProvider client={client} context={devtoolsOptions.context}>
18
19
  <ReactQueryDevtools {...devtoolsOptions} />
19
20
  {ui}
20
21
  </QueryClientProvider>,
22
+ renderOptions,
21
23
  )
22
24
  return {
23
25
  ...result,
package/src/devtools.tsx CHANGED
@@ -247,26 +247,37 @@ export function ReactQueryDevtools({
247
247
  }, [isResolvedOpen])
248
248
 
249
249
  React.useEffect(() => {
250
- if (isResolvedOpen) {
251
- const root = rootRef.current
250
+ if (isResolvedOpen && rootRef.current?.parentElement) {
251
+ const { parentElement } = rootRef.current
252
252
  const styleProp = getSidedProp('padding', panelPosition)
253
253
  const isVertical = isVerticalSide(panelPosition)
254
- const previousValue = root?.parentElement?.style[styleProp]
254
+
255
+ const previousPaddings = (({
256
+ padding,
257
+ paddingTop,
258
+ paddingBottom,
259
+ paddingLeft,
260
+ paddingRight,
261
+ }) => ({
262
+ padding,
263
+ paddingTop,
264
+ paddingBottom,
265
+ paddingLeft,
266
+ paddingRight,
267
+ }))(parentElement.style)
255
268
 
256
269
  const run = () => {
257
- if (root?.parentElement) {
258
- // reset the padding
259
- root.parentElement.style.padding = '0px'
260
- root.parentElement.style.paddingTop = '0px'
261
- root.parentElement.style.paddingBottom = '0px'
262
- root.parentElement.style.paddingLeft = '0px'
263
- root.parentElement.style.paddingRight = '0px'
264
- // set the new padding based on the new panel position
265
-
266
- root.parentElement.style[styleProp] = `${
267
- isVertical ? devtoolsWidth : devtoolsHeight
268
- }px`
269
- }
270
+ // reset the padding
271
+ parentElement.style.padding = '0px'
272
+ parentElement.style.paddingTop = '0px'
273
+ parentElement.style.paddingBottom = '0px'
274
+ parentElement.style.paddingLeft = '0px'
275
+ parentElement.style.paddingRight = '0px'
276
+ // set the new padding based on the new panel position
277
+
278
+ parentElement.style[styleProp] = `${
279
+ isVertical ? devtoolsWidth : devtoolsHeight
280
+ }px`
270
281
  }
271
282
 
272
283
  run()
@@ -276,9 +287,12 @@ export function ReactQueryDevtools({
276
287
 
277
288
  return () => {
278
289
  window.removeEventListener('resize', run)
279
- if (root?.parentElement && typeof previousValue === 'string') {
280
- root.parentElement.style[styleProp] = previousValue
281
- }
290
+ Object.entries(previousPaddings).forEach(
291
+ ([property, previousValue]) => {
292
+ parentElement.style[property as keyof typeof previousPaddings] =
293
+ previousValue
294
+ },
295
+ )
282
296
  }
283
297
  }
284
298
  }