Skip to content
This repository was archived by the owner on May 15, 2019. It is now read-only.

Commit a9315ce

Browse files
author
David Flanagan
committed
Fallback to MathJAX on any Katex error, not just parse errors
Summary: Bugs CP-879 and CP-1742 are caused by a TypeError thrown by KaTeX. We already fall back to MathJAX rendering when KaTeX throws a parse error. But currently we rethrow other kinds of errors. This patch changes that so we fallback to MathJAX for any kind of KaTeX error. The underlying KaTeX error has been fixed upstream and will go away when we upgrade webapp to use KaTeX 1.0. Since we've got the MathJAX fallback, however, it seems worth using it in case other errors arise in the future. Test Plan: Visit the following URL with this patch and verifies that it renders: http://localhost:8081/math/k-8-grades/fr-v2-terminale-s/fr-v2-matrices-enseignement-de-spcialit/fr-v2-oprations-sur-les-matrices/a/multiplying-matrices-by-scalars?lang=fr Reviewers: kevinb, michaelpolyak Reviewed By: kevinb Subscribers: tom Differential Revision: https://phabricator.khanacademy.org/D50139
1 parent 9ed4999 commit a9315ce

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

js/tex.jsx

+18-5
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,24 @@ const TeX = createReactClass({
241241
),
242242
};
243243
} catch (e) {
244-
/* jshint -W103 */
245-
if (e.__proto__ !== katex.ParseError.prototype) {
246-
/* jshint +W103 */
247-
throw e;
248-
}
244+
// By catching the exception here and returning null
245+
// we will fall back to asyncronously rendering with
246+
// MathJAX.
247+
//
248+
// NOTE: formerly we only returned null if the error
249+
// was a parse error from Katex and re-threw any other errors.
250+
// But https://khanacademy.atlassian.net/browse/CP-879 and
251+
// https://khanacademy.atlassian.net/browse/CP-1742 were caused
252+
// by regular TypeError exceptions in Katex, so we might as
253+
// well fall back to MathJAX in that case as well. (The Katex
254+
// bug is fixed in the latest version and will stop happening
255+
// when we upgrade webapp to use Katex 1.0.)
256+
//
257+
// TODO: We could use Raven.captureMessage() to send a message
258+
// to Sentry when these errors occur if we want to get serious
259+
// about eliminating them. Such a message should include
260+
// window.location, props.children (the string of katex source)
261+
// and the error itself.
249262
return null;
250263
}
251264
},

0 commit comments

Comments
 (0)