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

Styles are missing when JavaScript is disabled #1145

Closed
lunar-debian opened this issue Feb 1, 2023 · 6 comments · Fixed by #1146
Closed

Styles are missing when JavaScript is disabled #1145

lunar-debian opened this issue Feb 1, 2023 · 6 comments · Fixed by #1146

Comments

@lunar-debian
Copy link
Contributor

Thanks to everyone who worked on this amazing theme.

When JavaScript is disabled, data-theme is not set in the <html> tag, resulting in missing styles. #959 exhibited a similar problem but was ultimately solved by tweaking for CloudFlare specific behaviors.

An easy way to test this is to use any local JavaScript blocker. uBlock Origin will do nicely. See example video:
Kooha-2023-02-01-12:15:45.webm

One fix would be to modify CSS to better behave when data-theme is not set. Another would be to write the data-theme when writing the HTML files. Possibly this could be done only when default_mode is set in html_context.

@12rambau
Copy link
Collaborator

12rambau commented Feb 1, 2023

before we start losing hair on this one, could you describe in which context you run the theme with disabled javascript?
Because without any JS, there are actually a lot of functionalities that will fail:

  • secondary sidebar
  • scrollspy
  • search popup
  • version switcher
  • and of course theming

@lunar-debian
Copy link
Contributor Author

In this specific case, I noticed because the Content Security Policy on the artifacts server prevented JavaScript to run. But in general, we don’t have control on the browser configuration of our users. Degrading gracefully when JavaScript is disabled would be nice. Having two logos in the header made the documentation feel broken (and I’m afraid unmaintained).

@12rambau
Copy link
Collaborator

12rambau commented Feb 1, 2023

ok so let's get rid of the annoying things in this degraded env before trying something in a PR:

  • what happened to the search btn?
  • what happens when you have a secondary sidebar (If it's displayed, that's good enough)
  • remove any version switcher, as it won't work

@lunar-debian
Copy link
Contributor Author

lunar-debian commented Feb 1, 2023

ok so let's get rid of the annoying things in this degraded env before trying something in a PR:

  • what happened to the search btn?

Screenshot of the search button and theme switcher button when JavaScript is disabled

The search button is there, but clicking on it does nothing.
The theme button is reduced to its border.

I guess both should only appear when JavaScript is enabled?

  • what happens when you have a secondary sidebar (If it's displayed, that's good enough)

image

Both sidebar works. Toggling sections works just fine.

  • remove any version switcher, as it won't work

There is none in our case.

@12rambau
Copy link
Collaborator

12rambau commented Feb 1, 2023

ok so first step recover the search function and remove the items that you cannot use:

in your conf.py add back the search TextField in the sidebar or the navbar:

html_theme_options = {
    "navbar_end": ["search-field","navbar-icon-links"], # add the search field in the navbar and remove theme switch
    "navbar_persistent": [], # remove search button as it cannot be used anyway
}

lunar-debian pushed a commit to lunar-debian/pydata-sphinx-theme that referenced this issue Feb 2, 2023
Support for light/dark themes has been implemented using a `data-theme`
attribute set on the `<html/>` tag. As this attribute is set using
JavaScript, this meant that it was left unset when visitors had
JavaScript disabled. This resulted in several important CSS rules not
being matched and a “broken feeling” due to wrong colors, and logo or
images shown twice.

To better support browsers with JavaScript disabled:

1. Add the same CSS rules as for the light theme when the `data-theme`
   attribute is not set. This creates a safe fallback in every
   situation.
2. If `default_mode` is set, write its value to the `data-theme` attribute
   when writing the HTML files. This enables theme users to present
   their preferred mode to visitors with JavaScript disabled.
3. Use JavaScript to add the search and theme switcher buttons as they
   require JavaScript to work. This avoid unusable UI elements to be
   shown to visitors with JavaScript disabled.
4. Use JavaScript to write the logo for the “other theme”, depending on
   the value of `default_mode`, defaulting to “light” if unset.

While this last change might seem redundant considering the other ones,
it does make the resulting pages better for search engines and text
browsers.

Closes: pydata#1145
@lunar-debian
Copy link
Contributor Author

I am afraid you misunderstood our needs, so I went ahead and implemented some improvements. The issue is not that we want JavaScript to be disabled for all users. It is that some of our visitors might have JavaScript disabled and we are worried the broken aspect of the documentation will turn them away. Ideally the documentation UX should be better when JavaScript is enabled, but perfectly usable without. #1146 should fix the most visible problems.

lunar-debian pushed a commit to lunar-debian/pydata-sphinx-theme that referenced this issue Feb 6, 2023
Support for light/dark themes has been implemented using a `data-theme`
attribute set on the `<html/>` tag. As this attribute is set using
JavaScript, this meant that it was left unset when visitors had
JavaScript disabled. This resulted in several important CSS rules not
being matched and a “broken feeling” due to wrong colors, and logo or
images shown twice.

To better support browsers with JavaScript disabled:

1. Add the same CSS rules as for the light theme when the `data-theme`
   attribute is not set. This creates a safe fallback in every
   situation.
2. If `default_mode` is set, write its value to the `data-theme` attribute
   when writing the HTML files. This enables theme users to present
   their preferred mode to visitors with JavaScript disabled.
3. Use JavaScript to add the search and theme switcher buttons as they
   require JavaScript to work. This avoid unusable UI elements to be
   shown to visitors with JavaScript disabled.
4. Use JavaScript to write the logo for the “other theme”, depending on
   the value of `default_mode`, defaulting to “light” if unset.

While this last change might seem redundant considering the other ones,
it does make the resulting pages better for search engines and text
browsers.

Closes: pydata#1145
lunar-debian pushed a commit to lunar-debian/pydata-sphinx-theme that referenced this issue Feb 8, 2023
Support for light/dark themes has been implemented using a `data-theme`
attribute set on the `<html/>` tag. As this attribute is set using
JavaScript, this meant that it was left unset when visitors had
JavaScript disabled. This resulted in several important CSS rules not
being matched and a “broken feeling” due to wrong colors, and logo or
images shown twice.

To better support browsers with JavaScript disabled:

1. Add the same CSS rules as for the light theme when the `data-theme`
   attribute is not set. This creates a safe fallback in every
   situation.
2. If `default_mode` is set, write its value to the `data-theme` attribute
   when writing the HTML files. This enables theme users to present
   their preferred mode to visitors with JavaScript disabled.
3. Use JavaScript to add the search, theme switcher and version switcher
   interface as they require JavaScript to work. This avoid unusable UI
   elements to be shown to visitors with JavaScript disabled.
4. Use JavaScript to write the logo for the “other theme”, depending on
   the value of `default_mode`, defaulting to “light” if unset.
5. Use JavaScript to write the announcement block to the HTML if the
   announcement is a remote URL.

While this last change might seem redundant considering the other ones,
it does make the resulting pages better for search engines and text
browsers.

Closes: pydata#1145
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 a pull request may close this issue.

2 participants