Fix immediate window open defaults and error handling (#29417)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
yyh
2025-12-10 19:12:14 +08:00
committed by GitHub
parent ea063a1139
commit ec3a52f012
2 changed files with 81 additions and 4 deletions

View File

@@ -17,8 +17,18 @@ export const useAsyncWindowOpen = () => useCallback(async (getUrl: GetUrl, optio
onError,
} = options ?? {}
const secureImmediateFeatures = features ? `${features},noopener,noreferrer` : 'noopener,noreferrer'
if (immediateUrl) {
window.open(immediateUrl, target, features)
const newWindow = window.open(immediateUrl, target, secureImmediateFeatures)
if (!newWindow) {
onError?.(new Error('Failed to open new window'))
return
}
try {
newWindow.opener = null
}
catch { /* noop */ }
return
}