Skip to content

The agent that grows with you

fix(desktop): isolate a failed lazy syntax-diff import from the workspace pane

chelsealongb614e2656b70
diff --git a/apps/desktop/src/components/chat/diff-lines.test.tsx b/apps/desktop/src/components/chat/diff-lines.test.tsx
new file mode 100644
index 00000000000..d33be05f18a
--- /dev/null
+++ b/apps/desktop/src/components/chat/diff-lines.test.tsx
@@ -0,0 +1,63 @@
+import { act, cleanup, render } from '@testing-library/react'
+import { afterEach, describe, expect, it, vi } from 'vitest'
+
+// Regression coverage for #93479: a failed dynamic import of the lazily-loaded
+// Shiki diff module (packaged asar/asar.unpacked path mismatch, or any other
+// fetch failure) rejects the `React.lazy()` promise. React.Suspense only
+// covers the *pending* state, so the rejection throws past it to the nearest
+// error boundary — which in production is the whole workspace `ContribBoundary`
+// — and blanks the transcript instead of degrading to the plain colored diff.
+vi.mock('./syntax-diff', () => {
+ throw new Error(
+ 'Failed to fetch dynamically imported module: file:///Hermes.app/Contents/Resources/app.asar/dist/assets/syntax-diff-Bo0962zh.js'
+ )
+})
+
+import { ErrorBoundary } from '@/components/error-boundary'
+
+import { FileDiffPanel } from './diff-lines'
+
+afterEach(cleanup)
+
+const DIFF = [
+ 'diff --git a/file.ts b/file.ts',
+ '--- a/file.ts',
+ '+++ b/file.ts',
+ '@@ -1,2 +1,2 @@',
+ ' const a = 1',
+ '-const b = 2',
+ '+const b = 3'
+].join('\n')
+
+const WORKSPACE_FALLBACK_TEXT = 'workspace failed to render'
+
+// The failure surfaces only from console.error noise, not from the assertion.
+function renderQuietly(node: Parameters<typeof render>[0]) {
+ const spy = vi.spyOn(console, 'error').mockImplementation(() => undefined)
+
+ try {
+ return render(node)
+ } finally {
+ spy.mockRestore()
+ }
+}
+
+describe('FileDiffPanel survives a failed lazy syntax-diff chunk', () => {
+ it('degrades to the plain colored diff instead of taking down the surrounding boundary', async () => {
+ const { container } = renderQuietly(
+ <ErrorBoundary fallback={() => <div>{WORKSPACE_FALLBACK_TEXT}</div>} label="workspace">
+ <FileDiffPanel diff={DIFF} path="file.ts" />
+ </ErrorBoundary>
+ )
+
+ // The rejection settles a tick after the initial Suspense-pending render
+ // (which coincidentally shows the same plain text already) — give it
+ // real time to propagate before asserting nothing regressed.
+ await act(() => new Promise(resolve => setTimeout(resolve, 300)))
+
+ expect(container.textContent).toContain('const a = 1')
+ expect(container.textContent).toContain('const b = 2')
+ expect(container.textContent).toContain('const b = 3')
+ expect(container.textContent).not.toContain(WORKSPACE_FALLBACK_TEXT)
+ })
+})
diff --git a/apps/desktop/src/components/chat/diff-lines.tsx b/apps/desktop/src/components/chat/diff-lines.tsx
index 162e95c3f98..0f5731ec491 100644
--- a/apps/desktop/src/components/chat/diff-lines.tsx
+++ b/apps/desktop/src/components/chat/diff-lines.tsx
@@ -5,6 +5,7 @@ import type { BundledLanguage, ShikiTransformer, ThemedToken } from 'shiki'
import { chunkLines, type LineChunk, useFixedRowWindow } from '@/components/chat/fixed-row-window'
import { exceedsHighlightBudget, SHIKI_THEME } from '@/components/chat/shiki-highlighter'
+import { ErrorBoundary } from '@/components/error-boundary'
import { shikiLanguageForFilename } from '@/lib/markdown-code'
import { cn } from '@/lib/utils'
@@ -469,10 +470,18 @@ function SyntaxDiff({ language, lines }: { language: string; lines: DiffLine[] }
// The Shiki hook lives in a lazily-loaded module (syntax-diff.tsx) so the
// multi-MB shiki chunk stays off the cold-start path. Until it (and the
// highlight itself) resolves, show the plain colored diff — no flash.
+ //
+ // A rejected dynamic import (e.g. a packaged app whose renderer window is
+ // pointed at the asar copy of dist/ while the chunk only exists in
+ // app.asar.unpacked, #93479) throws past Suspense, which only covers the
+ // pending state. Without a local boundary that throw reaches the workspace
+ // ContribBoundary and blanks the whole pane instead of just this diff.
return (
- <React.Suspense fallback={<DiffBody lines={lines} />}>
- <LazySyntaxDiff language={language} lines={lines} />
- </React.Suspense>
+ <ErrorBoundary fallback={() => <DiffBody lines={lines} />} label="syntax-diff">
+ <React.Suspense fallback={<DiffBody lines={lines} />}>
+ <LazySyntaxDiff language={language} lines={lines} />
+ </React.Suspense>
+ </ErrorBoundary>
)
}