From 281f5647ea2cc6a944651466f0841140a7bc7d7b Mon Sep 17 00:00:00 2001 From: Nisha Yerunkar Date: Thu, 14 Nov 2024 11:41:59 -0800 Subject: [PATCH] [Locked Figure Labels] Fix bug that's causing the editor to crash when the label input is empty (and on load) (#1856) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary: I need to add a null check after my $ TeX updates in https://github.com/Khan/perseus/pull/1847. This is actually already added in a larger PR, but this fix needs to get out ASAP. Issue: none ## Test plan: - Go to http://localhost:6006/iframe.html?id=perseuseditor-widgets-interactive-graph--mafs-with-locked-figure-labels-all-flags&viewMode=story - Backspace in the locked point visible label input field - Confirm that there is no crash Author: nishasy Reviewers: benchristel, catandthemachines, anakaren-rojas Required Reviewers: Approved By: benchristel Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: https://github.com/Khan/perseus/pull/1856 --- .changeset/dry-moles-notice.md | 5 +++++ packages/perseus/src/widgets/interactive-graphs/utils.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/dry-moles-notice.md diff --git a/.changeset/dry-moles-notice.md b/.changeset/dry-moles-notice.md new file mode 100644 index 0000000000..3c17aa4955 --- /dev/null +++ b/.changeset/dry-moles-notice.md @@ -0,0 +1,5 @@ +--- +"@khanacademy/perseus": patch +--- + +[Locked Figure Labels] Fix bug that's causing the editor to crash when the label input is empty (and on load) diff --git a/packages/perseus/src/widgets/interactive-graphs/utils.ts b/packages/perseus/src/widgets/interactive-graphs/utils.ts index 08ac235102..bc25cc0f60 100644 --- a/packages/perseus/src/widgets/interactive-graphs/utils.ts +++ b/packages/perseus/src/widgets/interactive-graphs/utils.ts @@ -109,9 +109,13 @@ type ParsedNode = { // Helper function for replaceOutsideTeX() // Condense adjacent text nodes into a single text node -function condenseTextNodes(nodes: Array): Array { +function condenseTextNodes(nodes: ParsedNode[] | undefined): Array { const result: ParsedNode[] = []; + if (!nodes) { + return result; + } + let currentText = ""; for (const node of nodes) { if (node.type === "math") {