Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/warm-drinks-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/query-devtools': patch
---

fix(devtools): handle PiP open failures by resetting persisted state
22 changes: 17 additions & 5 deletions packages/query-devtools/src/contexts/PiPContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type PiPContextType = {
disabled: boolean
}

class PipOpenError extends Error {}

const PiPContext = createContext<Accessor<PiPContextType> | undefined>(
undefined,
)
Expand Down Expand Up @@ -57,7 +59,7 @@ export const PiPProvider = (props: PiPProviderProps) => {
)

if (!pip) {
throw new Error(
throw new PipOpenError(
'Failed to open popup. Please allow popups for this site to view the devtools in picture-in-picture mode.',
)
}
Expand Down Expand Up @@ -134,10 +136,20 @@ export const PiPProvider = (props: PiPProviderProps) => {
createEffect(() => {
const pip_open = (props.localStore.pip_open ?? 'false') as 'true' | 'false'
if (pip_open === 'true' && !props.disabled) {
requestPipWindow(
Number(window.innerWidth),
Number(props.localStore.height || PIP_DEFAULT_HEIGHT),
)
try {
requestPipWindow(
Number(window.innerWidth),
Number(props.localStore.height || PIP_DEFAULT_HEIGHT),
)
} catch (error) {
if (error instanceof PipOpenError) {
console.error(error.message)
props.setLocalStore('pip_open', 'false')
props.setLocalStore('open', 'false')
return
}
throw error
}
}
})

Expand Down
Loading