Skip to content

Commit

Permalink
Don't throw for unhandled messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremywiebe committed Sep 5, 2024
1 parent 7c0b92c commit 12ecccd
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/perseus-editor/src/iframe-content-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* to get the data to render. When the iframe is loaded, it's javascript sends
* a message to the parent, which triggers the parent to send the current data.
*/
import {UnreachableCaseError} from "@khanacademy/wonder-stuff-core";
import * as React from "react";

import {
Expand All @@ -24,6 +23,12 @@ let nextIframeID = 0;
const requestIframeData: Record<string, any> = {};
const updateIframeHeight: Record<string, any> = {};

/**
* Processes a message sent to the iframe parent (ie. this component).
*
* Note that this handler also sees messages sent from itself to the iframe so
* we intentionally ignore those here.
*/
function processIframeParentMessage(message: MessageToIFrameParent) {
if (!isPerseusMessage(message)) {
return;
Expand All @@ -45,7 +50,12 @@ function processIframeParentMessage(message: MessageToIFrameParent) {
return;

default:
throw new UnreachableCaseError(messageType);
// This is a type assertion that ensures we handle all of the types
// of messages we handle. We do _not_ throw an UnreachableCaseError
// here because this handler also sees messages sent from this
// component and those are not currently filtered by
// isPerseusMessage().
const _: never = messageType;
}
}

Expand Down

0 comments on commit 12ecccd

Please sign in to comment.