Skip to content

Commit

Permalink
🐛 Guard outputs and fix embed children (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 authored Aug 9, 2023
1 parent d98221f commit f8ab986
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-crabs-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@myst-theme/jupyter': patch
---

Fix embed node to render all children.
5 changes: 5 additions & 0 deletions .changeset/tiny-ghosts-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@myst-theme/jupyter': patch
---

Guard output if null or undefined
8 changes: 1 addition & 7 deletions packages/jupyter/src/embed.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { type GenericNode } from 'myst-common';
import { JupyterOutput } from './output';
import { OutputDecoration } from './decoration';
import { MyST } from 'myst-to-react';

Expand All @@ -13,12 +12,7 @@ export function Embed({ node }: { node: GenericNode }) {
title={node.source?.title}
url={node.source?.url}
>
<JupyterOutput
outputId={output.id}
identifier={output.identifier}
align={node.align}
data={node.data}
/>
<MyST ast={node.children} />
</OutputDecoration>
);
}
1 change: 1 addition & 0 deletions packages/jupyter/src/output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function allOutputsAreSafe(
directOutputTypes: Set<string>,
directMimeTypes: Set<string>,
) {
if (!outputs || outputs.length === 0) return true;
return outputs.reduce((flag, output) => {
if (directOutputTypes.has(output.output_type)) return flag && true;
const data = (output as MinifiedMimeOutput).data;
Expand Down
1 change: 1 addition & 0 deletions packages/jupyter/src/safe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function SafeOutput({ output }: { output: MinifiedOutput }) {
}

export function SafeOutputs({ keyStub, outputs }: { keyStub: string; outputs: MinifiedOutput[] }) {
if (!outputs) return null;
// TODO better key - add keys during content creation?
const components = outputs.map((output, idx) => (
<SafeOutput key={`${keyStub}-${idx}`} output={output} />
Expand Down

0 comments on commit f8ab986

Please sign in to comment.