fix(invoices): stop popup blockers from silently eating the PDF preview tab (#1191)
* fix(invoices): stop popup blockers from silently eating the PDF preview tab A window.open() after an await runs outside the click's transient user activation (~5s, less in Safari), so the preview tab was popup-blocked exactly when generation was slow (cold start + logo re-encode). The request succeeded, nothing opened, no error: the button looked locked (support: carina@cbysea.se). - lib/browser/deferred-tab.ts: open the tab synchronously in the click, navigate it when the result arrives, close it on failure (the pattern AGIPanel already used for its signing tab), with unit tests. - InvoiceEditor: preview uses the deferred tab + popup-blocked toast; revoke the blob URL instead of leaking it; guard the review dialog against an unresolved customer (silent no-op click); 5s timeout on the pre-review next-number fetch; spinner + disable while the submit handler is in flight in create mode. - Same pre-open fix in TransactionAttachmentIndicator, JournalEntryAttachments (failures now toast instead of vanishing), DocumentViewButton, and the Arcim reconnect OAuth popup (its 'trusted gesture' comment was wrong after the await). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(invoices): review triage: close blocked preview tab, precise popup hint, test convention Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
b5e3c476a5
commit
f07a34c51b
@@ -7,6 +7,7 @@ import { Paperclip, Loader2 } from 'lucide-react'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useToast } from '@/components/ui/use-toast'
|
||||
import { openDeferredTab } from '@/lib/browser/deferred-tab'
|
||||
|
||||
interface Props {
|
||||
documentId: string | null | undefined
|
||||
@@ -47,6 +48,7 @@ export function TransactionAttachmentIndicator({
|
||||
className,
|
||||
}: Props) {
|
||||
const t = useTranslations('tx_underlag')
|
||||
const tCommon = useTranslations('common')
|
||||
const { toast } = useToast()
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
|
||||
@@ -55,16 +57,28 @@ export function TransactionAttachmentIndicator({
|
||||
e.preventDefault()
|
||||
if (isLoading || !documentId) return
|
||||
setIsLoading(true)
|
||||
// Pre-open inside the click's user activation: a window.open after the
|
||||
// await is popup-blocked when the signed-URL fetch is slow.
|
||||
const tab = openDeferredTab(tCommon('loading'))
|
||||
try {
|
||||
const res = await fetch(`/api/documents/${documentId}`)
|
||||
if (!res.ok) {
|
||||
tab.close()
|
||||
toast({ title: t('open_failed'), variant: 'destructive' })
|
||||
return
|
||||
}
|
||||
const { data } = await res.json()
|
||||
if (data?.download_url) {
|
||||
window.open(data.download_url, '_blank', 'noopener,noreferrer')
|
||||
if (!data?.download_url || !tab.navigate(data.download_url)) {
|
||||
tab.close()
|
||||
toast({
|
||||
title: t('open_failed'),
|
||||
description: tab.blocked ? tCommon('popup_blocked_description') : undefined,
|
||||
variant: 'destructive',
|
||||
})
|
||||
}
|
||||
} catch {
|
||||
tab.close()
|
||||
toast({ title: t('open_failed'), variant: 'destructive' })
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user