Skip to content

Commit 0b29b6f

Browse files
akdlsz21TkDodo
andauthored
fix(devtools): handle PiP open failures by resetting persisted state (#9983)
fix: handle PiP open failures by resetting persisted state Co-authored-by: Dominik Dorfmeister <[email protected]>
1 parent 642f72d commit 0b29b6f

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

.changeset/warm-drinks-itch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/query-devtools': patch
3+
---
4+
5+
fix(devtools): handle PiP open failures by resetting persisted state

packages/query-devtools/src/contexts/PiPContext.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type PiPContextType = {
2626
disabled: boolean
2727
}
2828

29+
class PipOpenError extends Error {}
30+
2931
const PiPContext = createContext<Accessor<PiPContextType> | undefined>(
3032
undefined,
3133
)
@@ -57,7 +59,7 @@ export const PiPProvider = (props: PiPProviderProps) => {
5759
)
5860

5961
if (!pip) {
60-
throw new Error(
62+
throw new PipOpenError(
6163
'Failed to open popup. Please allow popups for this site to view the devtools in picture-in-picture mode.',
6264
)
6365
}
@@ -134,10 +136,20 @@ export const PiPProvider = (props: PiPProviderProps) => {
134136
createEffect(() => {
135137
const pip_open = (props.localStore.pip_open ?? 'false') as 'true' | 'false'
136138
if (pip_open === 'true' && !props.disabled) {
137-
requestPipWindow(
138-
Number(window.innerWidth),
139-
Number(props.localStore.height || PIP_DEFAULT_HEIGHT),
140-
)
139+
try {
140+
requestPipWindow(
141+
Number(window.innerWidth),
142+
Number(props.localStore.height || PIP_DEFAULT_HEIGHT),
143+
)
144+
} catch (error) {
145+
if (error instanceof PipOpenError) {
146+
console.error(error.message)
147+
props.setLocalStore('pip_open', 'false')
148+
props.setLocalStore('open', 'false')
149+
return
150+
}
151+
throw error
152+
}
141153
}
142154
})
143155

0 commit comments

Comments
 (0)