Skip to content

Commit

Permalink
Remove unnecessary MathJax 2 logic from Perseus.Init (#1833)
Browse files Browse the repository at this point in the history
## 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: #1833
  • Loading branch information
SonicScrewdriver authored Nov 7, 2024
1 parent 2a326b0 commit 122b3cc
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 46 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-hounds-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Removal of unused MathJax2 initialization
2 changes: 1 addition & 1 deletion packages/perseus/src/__tests__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
1 change: 0 additions & 1 deletion packages/perseus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
43 changes: 1 addition & 42 deletions packages/perseus/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<undefined> {
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<void>' is not assignable to type 'Promise<undefined>'.
return Promise.resolve();
}

return new Promise(
(
resolve: (result: Promise<never>) => 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;
Original file line number Diff line number Diff line change
Expand Up @@ -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)", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/widgets/grapher/grapher.cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down

0 comments on commit 122b3cc

Please sign in to comment.