Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary MathJax 2 logic from Perseus.Init #1833

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
44 changes: 3 additions & 41 deletions packages/perseus/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,19 @@ 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 (): Promise<undefined> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that there's nothing async in this function anymore, can you make it just 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);
},
);
// @ts-expect-error - TS2322 - Type 'Promise<void>' is not assignable to type 'Promise<undefined>'.
return Promise.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