Skip to content

Commit e913d69

Browse files
committed
fix(files): reset preview error boundary on content change, log component stack
Key the boundary (not the child) by file id + data version so a tripped boundary remounts and retries when the preview content updates, and include React's componentStack in crash logs.
1 parent 1d06dd9 commit e913d69

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/file-viewer.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,8 @@ const IframePreview = memo(function IframePreview({
146146
}
147147

148148
return (
149-
<PreviewErrorBoundary label='PDF'>
150-
<PdfViewerCore
151-
key={`${file.id}:${preview.dataUpdatedAt}`}
152-
source={bufferSource}
153-
filename={file.name}
154-
/>
149+
<PreviewErrorBoundary key={`${file.id}:${preview.dataUpdatedAt}`} label='PDF'>
150+
<PdfViewerCore source={bufferSource} filename={file.name} />
155151
</PreviewErrorBoundary>
156152
)
157153
})

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/preview-shared.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { Component, type ReactNode } from 'react'
3+
import { Component, type ErrorInfo, type ReactNode } from 'react'
44
import { createLogger } from '@sim/logger'
55
import { cn } from '@/lib/core/utils/cn'
66

@@ -33,6 +33,10 @@ interface PreviewErrorBoundaryState {
3333
* a preview module whose dynamic import rejected) and degrades to the standard
3434
* PreviewError fallback instead of unwinding to the route-level error boundary
3535
* and replacing the whole workspace view.
36+
*
37+
* Callers must `key` this boundary by the identity of the rendered content
38+
* (e.g. file id + data version) — the error state resets only via remount, so
39+
* keying the child alone would leave a tripped boundary stuck on the fallback.
3640
*/
3741
export class PreviewErrorBoundary extends Component<
3842
PreviewErrorBoundaryProps,
@@ -46,8 +50,12 @@ export class PreviewErrorBoundary extends Component<
4650
return { hasError: true, error }
4751
}
4852

49-
public componentDidCatch(error: Error) {
50-
logger.error('Preview crashed', { label: this.props.label, error: error.message })
53+
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
54+
logger.error('Preview crashed', {
55+
label: this.props.label,
56+
error: error.message,
57+
componentStack: errorInfo.componentStack,
58+
})
5159
}
5260

5361
public render() {

0 commit comments

Comments
 (0)