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 mathjax form main xmodule requirement and add it on problem addin... #6048

Conversation

zubair-arbi
Copy link
Contributor

@zubair-arbi zubair-arbi force-pushed the zub/bugfix/tnl-823-remove-mathjax-from-main-dependency branch from ef3d181 to 6642c4d Compare November 25, 2014 14:21
@adampalay
Copy link
Contributor

unfortunately, we still need mathjax on every unit in studio. Is there a way to load it, but not as a dependency?

@zubair-arbi
Copy link
Contributor Author

@adampalay I also added mathjax in studio_xblock_wrapper so now mathjax will also work for html or other components which don't use formula_equation_preview.js.
Also now if mathjax will fail to load then page will render fine since it is not in main require dependency.

@zubair-arbi
Copy link
Contributor Author

You can test on sandbox here http://studio.zubair-arbi.m.sandbox.edx.org

@zubair-arbi
Copy link
Contributor Author

@andy-armstrong can you please review and check if the change is reasonable?

@adampalay
Copy link
Contributor

It feels faster to load a unit now!

Question: if mathjax is slow to load, or doesn't load, will that mean that xblocks will be slow to load--or blocked from loading--in studio?

@@ -169,4 +169,11 @@ formulaEquationPreview.enable = function () {
$('.formulaequationinput input').each(setupInput);
};

formulaEquationPreview.enable();
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

We aren't using requireJS in the LMS currently (although we're edging towards using it). I'm nervous that this isn't going to work there. Have you tested this in the LMS?

@cahrens Are you familiar with how this works?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change even necessary given the studio wrapper change? Or is it still needed so that this code doesn't run before the wrapper async process completes? Does there need to be similar logic in every usage of MathJax?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andy-armstrong You are right about that requireJS is not being used in LMS that's why I added try-catch block. Since display method inside updatePage method uses mathjax that's why I added a separate dependency here to be on safe side (like if mathjax not loaded first time with xblock_wrapper for some reason then loading this file will try again to load mathjax) so this change is not necessary.

Copy link

Choose a reason for hiding this comment

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

I don't think that whether or not require exists is a valid way of telling CMS vs. LMS. If you expect mathjax to be on the window object, check if it is (and when RequireJS is added to LMS, make sure that the config says that mathjax exports the right thing).

@andy-armstrong
Copy link
Contributor

The sandbox isn't working for me. It never even gets to the login page.

<script type="text/javascript">
$( document ).ready(function() {
require(['jquery', 'mathjax'], function() {
window.MathJax = MathJax;
Copy link

Choose a reason for hiding this comment

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

Is there any dependency between this code and the change below (formula_equation_preview.js)? Does window.MathJax need to be defined before formulaEquationPreview.enable() is executed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cahrens since mathjax could be needed on every unit page e.g, a user puts some math content "(\frac{3}{4})" in html component which don't requires ormula_equation_preview.js so I added mathjax dependency here since xblock wrapper is added with each xblock. Also since this is a soft dependency so if mathjax won't load for some reason then page will render just fine.
For formula_equation_preview.js formulaEquationPreview.enable() requires mathjax (hard dependency) so I added separate requirement for that method (if mathjax is not loaded with xblock_wrapper then it will try again).

Copy link

Choose a reason for hiding this comment

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

Why the dependency on JQuery?

If we go this approach, a big comment is needed here explaining what is going on.

What does the user see if MathJax is needed? Since this is in document ready, will there be an additional delay for the text is rendered (does it render in a different font and then re-render)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right I shouldn't add dependency on JQuery.
Since mathjax will load after the page is rendered (with normal font) so after mathjax is loaded it will re-render (with mathjax font).

@zubair-arbi
Copy link
Contributor Author

@andy-armstrong I have rechecked sanbox is working http://zubair-arbi.m.sandbox.edx.org/

@zubair-arbi
Copy link
Contributor Author

@cahrens @andy-armstrong does these changes look reasonable?

formulaEquationPreview.enable();
try {
require(['jquery', 'mathjax'], function() {
formulaEquationPreview.enable();
Copy link

Choose a reason for hiding this comment

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

I'm still nervous if this will work properly when part of the LMS is using requireJS (per the PR that is about to merge). We need to make sure that the RequireJS config there exports mathjax on the window object. I'd prefer to hold on this PR until #6158 merges, and then update the require config if necessary.

@cahrens
Copy link

cahrens commented Dec 8, 2014

Another thing to keep in mind-- xmodules exist in other places in Studio besides the unit/container page. For example, static pages and course info (I'm not 100% positive that course info uses xmodules, but static pages certainly does). So we would need to make sure that the right thing happens in those locations as well.

👎 I think more thought is needed on this change.

@zubair-arbi
Copy link
Contributor Author

@cahrens I have checked the static pages and course info (updates and handouts) don't use mathjax. You can check by adding some math expression like "(\frac{3}{4})".
You are right that we should wait for #6158 to merge and think how to resolve this issue properly. Can you please give an idea how to proceed with resolving this issue?

@cahrens
Copy link

cahrens commented Dec 11, 2014

Note that the first PR introducing RequireJS is now in master-- https://github.com/edx/edx-platform/pull/5829.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants