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

Fails after updating to Sphinx 3.5.1 #68

Closed
championshuttler opened this issue Feb 18, 2021 · 10 comments
Closed

Fails after updating to Sphinx 3.5.1 #68

championshuttler opened this issue Feb 18, 2021 · 10 comments

Comments

@championshuttler
Copy link

Mermaid graphs are not rendering https://firefox-source-docs.mozilla.org/tools/moztreedocs/mermaid-integration.html after upgrading to 3.5.1 we are getting this errro Uncaught ReferenceError: mermaid is not defined

@gil-obradors
Copy link

gil-obradors commented Feb 21, 2021

Hi !

I have the same problem. But I fix it.

I can't found mermaid.js downloaded on _static files, so Sphinx doesn't download it.
So the browser doesn't load mermaid.js packages, and can't find mermaid.* references for rendering.

I have resolved it:

  • downloading the file from CDN wget https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.9.1/mermaid.js,
  • put it into _static/js`
  • and put this directive to config.py : html_js_files = [ 'js/mermaid.js', ]

Check if it works for you!

I will try to find why isn't downloaded automatically, or create a PR advertising of that on readme.md

Good luck!

@championshuttler
Copy link
Author

Yeah we did the same in last but instead of downloading the js file i am rendering it directly https://searchfox.org/mozilla-central/source/docs/conf.py#77 , earlier we used to have this post script to render on every page https://phabricator.services.mozilla.com/D105674

@championshuttler
Copy link
Author

Hi !

I have the same problem. But I fix it.

I can't found mermaid.js downloaded on _static files, so Sphinx doesn't download it.
So the browser doesn't load mermaid.js packages, and can't find mermaid.* references for rendering.

I have resolved it:

  • downloading the file from CDN wget https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.9.1/mermaid.js,
  • put it into _static/js`
  • and put this directive to config.py : html_js_files = [ 'js/mermaid.js', ]

Check if it works for you!

I will try to find why isn't downloaded automatically, or create a PR advertising of that on readme.md

Good luck!

I guess in the latest Sphinx 3.5.1 they removed some functionality i am not sure though thats why sphinx is not able to find mermaid script in _static

@gil-obradors
Copy link

gil-obradors commented Feb 21, 2021

I think i found it.

@mgaitan is posible that may be load need to change this method? register?

Changed in version 1.8: Renamed from app.add_javascript(). And it allows keyword arguments as attributes of script tag.

self.builder.script_files.append(self._mermaid_js_url)

sphinx-doc/sphinx#6088

@mgaitan
Copy link
Owner

mgaitan commented Feb 21, 2021

I've just committed a patch among a set of basic unit tests (finally!). Published 0.6.3

@gil-obradors you were right, that was the problem but needed to do that not in the setup nor the actual node handler but in a special function called via "html-page-context" signal (doing it in the setup makes the tests with conf overrides to fail).

I'm no sure if I've just broke compatibility with not so old sphinx versions I'd happily accept a PR to fix it if so).

@mgaitan mgaitan closed this as completed Feb 21, 2021
@iancze
Copy link

iancze commented Mar 19, 2021

I think I'm getting the same javascript error: Uncaught ReferenceError: mermaid is not defined.

I'm using sphinxcontrib-mermaid v0.6.3 and sphinx v3.5.2 (though this also failed on 3.4.3 before I upgraded). I had stumbled upon the solution outlined by @gil-obradors , which allowed things to work locally, but ultimately failed when I pushed to readthedocs.

@gil-obradors
Copy link

I'm on v0.6.2,
I will try v0.6.3 @iancze

@championshuttler
Copy link
Author

In Production, same happening with me, I am getting same error as @iancze

@hsuominen
Copy link

Seeing the same issue here

florianhumblot added a commit to florianhumblot/sphinxcontrib-mermaid that referenced this issue Oct 13, 2021
If the js script is local, the initialization code is inserted before the actual `mermaid.(min.)js` include which makes the init script error with `mermaid is undefined`.
According to: https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_js_file
The default prioirty for `app.add_js_file` is 500, while the default priority of `html_js_files` is 800. 

A different solution would be to pass the path to the local mermaid.js to this plugin and have it insert it at the right time but I am not familiar enough with this code base to make that change
@florianhumblot
Copy link
Contributor

@mgaitan I've proposed a fix for this issue which should be a more permanent solution to the problem.
Is there a way you can upstream the patch or fix it in another proposed way?
The PR with the proposed fix is #77

mgaitan added a commit that referenced this issue Nov 4, 2021
Fix #68 by setting mermaid init JS priority
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

No branches or pull requests

6 participants