From 122b3cc1b9b233e1014ec2176319af8bbb0c54ce Mon Sep 17 00:00:00 2001 From: Sarah Third Date: Thu, 7 Nov 2024 14:51:51 -0800 Subject: [PATCH] Remove unnecessary MathJax 2 logic from Perseus.Init (#1833) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary: While investigating a regression on Webapp related to our Deprecated Stand-in Widget, we discovered we were initializing MathJax unnecessarily! This initialization is specifically for MathJax2 so it is safe to remove entirely. Issue: LEMS-2588 ## Test plan: - Manual testing - Knowledge that this code has not been running for 2 months, and we've had zero issues with our MathJax rendering - Knowledge that this is unused due to being MathJax2 Author: SonicScrewdriver Reviewers: jeremywiebe, benchristel Required Reviewers: Approved By: jeremywiebe Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: https://github.com/Khan/perseus/pull/1833 --- .changeset/witty-hounds-melt.md | 5 +++ packages/perseus/src/__tests__/init.test.ts | 2 +- packages/perseus/src/index.ts | 1 - packages/perseus/src/init.ts | 43 +------------------ .../explanation/explanation.cypress.ts | 2 +- .../src/widgets/grapher/grapher.cypress.ts | 2 +- 6 files changed, 9 insertions(+), 46 deletions(-) create mode 100644 .changeset/witty-hounds-melt.md diff --git a/.changeset/witty-hounds-melt.md b/.changeset/witty-hounds-melt.md new file mode 100644 index 0000000000..7e053ccfd7 --- /dev/null +++ b/.changeset/witty-hounds-melt.md @@ -0,0 +1,5 @@ +--- +"@khanacademy/perseus": patch +--- + +Removal of unused MathJax2 initialization diff --git a/packages/perseus/src/__tests__/init.test.ts b/packages/perseus/src/__tests__/init.test.ts index 6d9676ae71..349abe8845 100644 --- a/packages/perseus/src/__tests__/init.test.ts +++ b/packages/perseus/src/__tests__/init.test.ts @@ -3,7 +3,7 @@ import {getWidget} from "../widgets"; describe("init", () => { it("should correctly replace the transformer widget", async () => { - await init({skipMathJax: true}); + await init(); expect(getWidget("transformer")).not.toBeNull(); }); diff --git a/packages/perseus/src/index.ts b/packages/perseus/src/index.ts index df9290e37b..26461c363c 100644 --- a/packages/perseus/src/index.ts +++ b/packages/perseus/src/index.ts @@ -159,7 +159,6 @@ export {default as WIDGET_PROP_DENYLIST} from "./mixins/widget-prop-denylist"; /** * Types */ -export type {PerseusOptions} from "./init"; export type {ILogger, LogErrorOptions} from "./logging/log"; export type {ServerItemRenderer as ServerItemRendererComponent} from "./server-item-renderer"; export type { diff --git a/packages/perseus/src/init.ts b/packages/perseus/src/init.ts index 8708b8fb4f..be79cf4c6d 100644 --- a/packages/perseus/src/init.ts +++ b/packages/perseus/src/init.ts @@ -2,57 +2,16 @@ import basicWidgets from "./basic-widgets"; import extraWidgets from "./extra-widgets"; import * as Widgets from "./widgets"; -declare const MathJax: any; - -export type PerseusOptions = { - // TODO(LEMS-1608): remove skipMathJax once we have completely removed the - // legacy MathJax 2 renderer from webapp. - skipMathJax: boolean; -}; - /** * This should be called by all clients, specifying whether extra widgets are * needed via `loadExtraWidgets`. It is idempotent, so it's not a problem to * call it multiple times. - * - * skipMathJax: - * If false/undefined, MathJax will be configured, and the - * promise will wait for MathJax to load (if it hasn't already). */ -const init = function (options: PerseusOptions): Promise { +const init = function () { Widgets.registerWidgets(basicWidgets); Widgets.registerWidgets(extraWidgets); Widgets.replaceDeprecatedWidgets(); - - // Pass skipMathJax: true if MathJax is already loaded and configured. - const skipMathJax = options.skipMathJax; - - if (skipMathJax) { - // @ts-expect-error - TS2322 - Type 'Promise' is not assignable to type 'Promise'. - return Promise.resolve(); - } - - return new Promise( - ( - resolve: (result: Promise) => void, - reject: (error?: any) => void, - ) => { - MathJax.Hub.Config({ - messageStyle: "none", - skipStartupTypeset: "none", - "HTML-CSS": { - availableFonts: ["TeX"], - imageFont: null, - scale: 100, - showMathMenu: false, - }, - }); - - MathJax.Hub.Configured(); - MathJax.Hub.Queue(resolve); - }, - ); }; export default init; diff --git a/packages/perseus/src/widgets/explanation/explanation.cypress.ts b/packages/perseus/src/widgets/explanation/explanation.cypress.ts index 4126300358..9c66e6ddf8 100644 --- a/packages/perseus/src/widgets/explanation/explanation.cypress.ts +++ b/packages/perseus/src/widgets/explanation/explanation.cypress.ts @@ -16,7 +16,7 @@ describe("Explanation Widget", () => { beforeEach(() => { Dependencies.setDependencies(cypressTestDependencies); - Perseus.init({skipMathJax: true}); + Perseus.init(); }); it("prevents interacting with actionable items within content when COLLAPSED (initial state)", () => { diff --git a/packages/perseus/src/widgets/grapher/grapher.cypress.ts b/packages/perseus/src/widgets/grapher/grapher.cypress.ts index 4baeff3b69..636b69b4dc 100644 --- a/packages/perseus/src/widgets/grapher/grapher.cypress.ts +++ b/packages/perseus/src/widgets/grapher/grapher.cypress.ts @@ -25,7 +25,7 @@ const LINES = "[data-interactive-kind-for-testing=movable-line] > svg > path"; describe("Grapher widget", () => { beforeEach(() => { - Perseus.init({skipMathJax: true}); + Perseus.init(); Perseus.Dependencies.setDependencies(cypressTestDependencies); });