fix: harden async window open placeholder logic(#29390)

This commit is contained in:
yyh 2025-12-10 12:55:02 +08:00
parent 681c06186e
commit 997ff45e56
No known key found for this signature in database
1 changed files with 13 additions and 13 deletions

View File

@ -24,21 +24,21 @@ export const useAsyncWindowOpen = () => {
const newWindow = window.open('', '_blank', windowFeatures)
if (!newWindow) {
const error = new Error('Popup blocked by browser')
onError?.(error)
Toast.notify({
type: 'error',
message: 'Popup blocked. Please allow popups for this site.',
})
return
}
try {
const url = await fetchUrl()
if (url) {
newWindow.location.href = url
if (newWindow) {
try {
newWindow.opener = null
}
catch { /* noop */ }
newWindow.location.href = url
}
else {
// Fallback: navigate current tab if we couldn't get a window reference
window.location.href = url
}
onSuccess?.(url)
if (successMessage) {
@ -49,7 +49,7 @@ export const useAsyncWindowOpen = () => {
}
}
else {
newWindow.close()
newWindow?.close()
const error = new Error('Invalid URL received')
onError?.(error)
Toast.notify({
@ -59,7 +59,7 @@ export const useAsyncWindowOpen = () => {
}
}
catch (error) {
newWindow.close()
newWindow?.close()
onError?.(error)
Toast.notify({
type: 'error',