-
Notifications
You must be signed in to change notification settings - Fork 329
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
adding requirejs dependency #149
Conversation
docs/conf.py
Outdated
@@ -76,6 +77,9 @@ | |||
"doc_path": "docs", | |||
} | |||
|
|||
jupyter_sphinx_require_url = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be set to null
so that jupyter-sphinx doesn't load its own version of requirejs
actually, now that I think about it I think it'd be better if we added all of the scripts using |
4d5dfa4
to
cb35ef2
Compare
I tried getting this to work with I am curious if @jorisvandenbossche is OK with bundling RequireJS as a part of this theme by default (about 18kb). Another option would be to make it an option, and to document the fact that if people need to run something that uses RequireJS, then they should enable it at the theme level and disable it at the extension level so we don't trigger the bootstrap bug. |
Thanks a lot for looking into this. I would at least add the option to turn if off? (similarly as nbsphinx and jupyter-sphinx do) |
OK, more experimenting, more weirdness:
So I concluded that we actually want requirejs after bootstrap loads So, this PR now adds requirejs after the bootstrapjs. I guess that was the problem - if you add js libraries with TBH I don't really know why this is a problem because it sounds like a javascript thing (maybe @hoetmaaiers has an idea?) Either way it seems to work, along with the docs section about using requirejs (also added in this PR) I also switched the example to use |
a8d8f37
to
0dfbb7a
Compare
Is there anything blocking this PR currently? |
I am not following the need for require.js inside this theme setup. What part of Sphinx requires 'require.js'? |
That's the tricky thing. This theme doesn't require any requirejs, but many extensions and packages in the pydata community (eg, jupyter-sphinx, plotly, and ipywidgets) do need it, and if they add it in the standard way to their sphinx build, it puts requirejs before bootstrap in the load order, which causes things to break |
I think that the cleaner solution here would be to get bootstrap loaded with "add_js_file" so we know it loads before require, but when I did that, it caused sphinx to load it twice and I have no idea why |
I am not familiar with require.js. It also is an older way of importing and bundling javascripts. The only thing I am also wondering why requirejs loaded before bootstraps breaks things. Is this a name collision (or maybe something global?) Is it possible to provide an example with the requires + bootstrap going wrong? |
I also goes far beyond my js world knowledge, but from googling, it seems relatively common that people run into problems with boostrap and requirejs ... So when requirejs is loaded first, you get "Error: Mismatched anonymous define() module:" errors in the browser console (and certain features of bootstrap don't work anymore). According to https://stackoverflow.com/questions/15371918/mismatched-anonymous-define-module/23467090#23467090, the solution is to either load the other js code before loading requirejs, or either to load it using requirejs.
Yes, will push a small commit to this branch that will trigger it. |
I pushed it to a separate branch to not mess up this PR: #150. If you look at the built demo docs: https://255-130237506-gh.circle-artifacts.com/0/html/index.html, I get the mentioned error in the browser console. |
This helps. I might have an idea for combining bootstrap and require.js this way. Maybe making correct use of Webpack and loading Bootstrap that way will help. I try to look into it soon. |
@choldgraf I am happy to have this merged in the meantime, even if @hoetmaaiers can find a better solution, if that helps you downstream. |
Based on @jorisvandenbossche separate branch, I managed to fix the requires error by importing bootstrap dependencies via Webpack and bundle over there. It is available on https://github.com/hoetmaaiers/pydata-bootstrap-sphinx-theme/tree/pr-150, what is the easiest to test if this works with the example package needing require (was it a plotly graph) , is it included in #150 ? |
closing this as @hoetmaaiers's fix seems to work quite nicely!! |
I was trying to get requirejs to work with Bootstrap, and I found that the only way I could do so was to load requirejs as a part of this theme, and then to disable loading it dynamically by any downstream plugins.
This was partially inspired by this issue: https://stackoverflow.com/questions/15371918/mismatched-anonymous-define-module/23467090#23467090
It seems like things behave unpredictably when
requirejs
is loaded by extensions etc, so this PR just loads it up-front and before it loads bootstrap, which seemed to be what the SO post recommended. I also added a little plotly example usingjupyter-sphinx
to test that this actually works (though feel free to recommend a more lightweight example if you can)closes #30