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

sphinx-tabs inadvertently removes css and js #183

Closed
peytondmurray opened this issue Nov 4, 2023 · 6 comments
Closed

sphinx-tabs inadvertently removes css and js #183

peytondmurray opened this issue Nov 4, 2023 · 6 comments
Labels

Comments

@peytondmurray
Copy link

peytondmurray commented Nov 4, 2023

Describe the bug

context
When I use the sphinx-tabs extension and I include css or js in specific pages, this function removes it even if I intend for it to be included.

expectation
I expect sphinx-tabs to leave my included css/js alone. Rather than including sphinx-tabs assets globally and then removing them upon html-page-context if the page doesn't have any tabs directives, this package should only insert those assets if the page does have a tabs directive, not the other way around. This can also be done at html-page-context time.

bug
Instead, sphinx-tabs automatically removes all css/js unless it is included on every single page.

problem
This is a problem for people who want to include assets on specific pages to keep page load times down, but who also want to use tabs. Both sphinx docs and pydata-sphinx-theme docs suggest inserting css/js assets upon html-page-context, so the current behavior is extremely confusing because your assets get removed in the background, leaving you wondering how this is happening.

Reproduce the bug

Here's a small working example: https://github.com/peytondmurray/minimalsphinx/tree/per-page-css

You'll see if you run make html that the apidocs.html will only include the css if sphinx-tabs is disabled.

List your environment

No response

Copy link

welcome bot commented Nov 4, 2023

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

Welcome to the EBP community! 🎉

@foster999
Copy link
Collaborator

This is potentially the same as #180, or caused by the fix of that issue. What version of the package are you using?

@foster999
Copy link
Collaborator

Thanks for including the example - this pins an earlier version, so please try it with the latest

@peytondmurray
Copy link
Author

peytondmurray commented Nov 4, 2023

@foster999 Thanks, you're absolutely right that upgrading fixed the issue. I looked at the differences between 3.4.1 and 3.4.4 and I'm stumped as to why this now works. Here's the difference:

image

What exactly does moving the slicing operation do here? v3.4.1 has

context["css_files"] = context["css_files"][:]

which in my mind means 'set the context["css_files"] list equal to the slice containing the entire list of context["css_files"]'. In v3.4.4 the relevant lines read 'set the slice containing the entire list of context["css_files"] equal to the list of context["css_files"].' Naively I would expect the operation in either case to do nothing, basically, but I must be wrong 🤷. I guess I'm not the only one struggling to understand this, did you ever figure it out?

@foster999
Copy link
Collaborator

Afraid I'm still baffled by the slicing too! My feeling was that it's something to do with updating all references to the object (and nested objects inside it) vs just updating the single reference. Kinda like shallow vs deep copying. But didn't understand how that lead to the issue.

I was surprised the issue hadn't come up sooner, though it seems to be themes rather than other extensions that were affected. So maybe something to do with the order that sphinx evaluates things 🤷

@peytondmurray
Copy link
Author

Thanks again for the help!

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

No branches or pull requests

2 participants