From 3d599f2c25754b496b7e19d04286ab158e63b068 Mon Sep 17 00:00:00 2001 From: Mark Miro Date: Fri, 6 Feb 2026 15:12:51 -0800 Subject: [PATCH] Add error boundary --- packages/components/src/index.ts | 3 + .../notebook-preview/src/NotebookRenderer.tsx | 79 +++++++++++-------- 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/packages/components/src/index.ts b/packages/components/src/index.ts index bd5714b2..bc3fc991 100644 --- a/packages/components/src/index.ts +++ b/packages/components/src/index.ts @@ -76,6 +76,9 @@ export { groupConsecutiveStreamOutputs } from "./utils/output-grouping.js"; export { OutputTypesDemoPage } from "./OutputTypesDemoPage.js"; export { Incrementor } from "./Incrementor.js"; +// Error boundary +export { ErrorBoundary } from "react-error-boundary"; + // Re-export types from schema for convenience export type { OutputData, diff --git a/packages/notebook-preview/src/NotebookRenderer.tsx b/packages/notebook-preview/src/NotebookRenderer.tsx index 32e1d250..9682c53a 100644 --- a/packages/notebook-preview/src/NotebookRenderer.tsx +++ b/packages/notebook-preview/src/NotebookRenderer.tsx @@ -5,6 +5,7 @@ import { SuspenseSpinner, ExecutionCount, SyntaxHighlighter, + ErrorBoundary, } from "@runtimed/components"; // Jupyter notebook types @@ -158,25 +159,31 @@ function CodeCell({ cell, language }: { cell: JupyterCell; language: string }) {
{/* Input */}
- Error rendering syntax highlighter
} > - {source} - + + {source} + +
{/* Outputs */} {outputs.length > 0 && (
- - - {outputs.map((output) => ( - - ))} - - + Error rendering outputs
}> + + + {outputs.map((output) => ( + + ))} + + + )} @@ -210,9 +217,11 @@ function MarkdownCell({ cell }: { cell: JupyterCell }) {
- - - + Error rendering markdown
}> + + + +
@@ -243,24 +252,26 @@ export function NotebookRenderer({ notebook }: { notebook: JupyterNotebook }) { return (
- {notebook.cells.map((cell, index) => { - switch (cell.cell_type) { - case "code": - return ( - - ); - case "markdown": - return ; - case "raw": - return ; - default: - return null; - } - })} + Error rendering notebook
}> + {notebook.cells.map((cell, index) => { + switch (cell.cell_type) { + case "code": + return ( + + ); + case "markdown": + return ; + case "raw": + return ; + default: + return null; + } + })} + ); }