@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/build/lib/__tests__/utils.d.ts +2 -2
- package/build/lib/devtools.esm.js +30 -18
- package/build/lib/devtools.esm.js.map +1 -1
- package/build/lib/devtools.js +30 -18
- package/build/lib/devtools.js.map +1 -1
- package/build/lib/devtools.mjs +30 -18
- package/build/lib/devtools.mjs.map +1 -1
- package/build/lib/index.prod.esm.js +30 -18
- package/build/lib/index.prod.esm.js.map +1 -1
- package/build/lib/index.prod.js +30 -18
- package/build/lib/index.prod.js.map +1 -1
- package/build/lib/index.prod.mjs +30 -18
- package/build/lib/index.prod.mjs.map +1 -1
- package/build/umd/index.development.js +30 -18
- package/build/umd/index.development.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/devtools.test.tsx +53 -1
- package/src/__tests__/utils.tsx +3 -1
- package/src/devtools.tsx +33 -19
package/package.json
CHANGED
|
@@ -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
|
})
|
package/src/__tests__/utils.tsx
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
|
|
280
|
-
|
|
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
|
}
|