sphinx-material icon indicating copy to clipboard operation
sphinx-material copied to clipboard

Search results shows up with Please activate JavaScript ... error

Open pradeepchawda opened this issue 2 years ago • 11 comments

We have been facing issue with one of the repo where even if javascript is enabled it shows the warning as well as results.

Is this a known issue? If yes, what is is recommended fix? If not, then can any one suggest a fix.

image

pradeepchawda avatar Jan 20 '23 00:01 pradeepchawda

Not sure why you are seeing this. I don't see it. Which browser? Does the same happen when you use a private window (no extensions)?

bashtage avatar Jan 20 '23 08:01 bashtage

Its safari Version 16.2 (18614.3.7.1.5). Also it happens in private window.

pradeepchawda avatar Jan 20 '23 16:01 pradeepchawda

Do you see it here? https://www.statsmodels.org/stable/search.html?q=ARMAX

bashtage avatar Jan 20 '23 17:01 bashtage

No. Also it happens only in a specific repo and other repo is working fine. I checked the conf.py and version its the same.

pradeepchawda avatar Jan 20 '23 17:01 pradeepchawda

It does not happen in local but in gitlab pages

pradeepchawda avatar Jan 20 '23 18:01 pradeepchawda

I have also encountered this problem. After my testing, I found that the issue does not occur when using Sphinx version less than 6.0. Should sphinx-material consider compatibility with the new version of Sphinx🤣?

macreeeeee avatar Mar 31 '23 07:03 macreeeeee

yes, it got fixed after i downgraded to 5.3

pradeepchawda avatar Apr 01 '23 03:04 pradeepchawda

This indeed looks like a bug in this theme, in combination with a newer Sphinx version. It's visible also in the docs of this theme itself, and it shows up when using support for multiple versions of the docs:

  • No warning in the default version: https://bashtage.github.io/sphinx-material/search.html?q=help
  • Warning visible in the devel version: https://bashtage.github.io/sphinx-material/devel/search.html?q=help

It indeed doesn't show up for statsmodels, probably because it uses the JS file version switching rather than the conf.py method: https://bashtage.github.io/sphinx-material/devel/customization.html#using-a-javascript-file.

rgommers avatar Feb 10 '24 12:02 rgommers

The problematic fallback code lives here: https://github.com/bashtage/sphinx-material/blob/0d31923e0fb08e85027c3e7f03d12673209872e3/sphinx_material/sphinx_material/search.html#L8. My JS foo is very weak, so not sure how Sphinx 6.x changes could affect that code.

rgommers avatar Feb 10 '24 12:02 rgommers

Looks like the issue is that Sphinx 5.0 and later no longer ship jQuery. Installing sphinxcontrib-jquery made the problem disappear.

rgommers avatar Mar 05 '24 16:03 rgommers

The issue can be fixed without adding a jQuery dependency by overriding your project's search page template.

Here's one possible solution with a noscript tag. _templates/search.html:

{%- extends "basic/search.html" %}

{% block body %}
  <h1 id="search-documentation">{{ _('Search') }}</h1>
  <noscript>
    <div id="fallback" class="admonition warning">
    <p>
      {% trans %}Please activate JavaScript to enable the search
      functionality.{% endtrans %}
    </p>
    </div>
  </noscript>
  {% if search_performed %}
    <h2>{{ _('Search Results') }}</h2>
    {% if not search_results %}
      <p>{{ _('Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.') }}</p>
    {% endif %}
  {% endif %}
  <div id="search-results">
  {% if search_results %}
    <ul>
    {% for href, caption, context in search_results %}
      <li><a href="{{ pathto(item.href) }}">{{ caption }}</a>
        <div class="context">{{ context|e }}</div>
      </li>
    {% endfor %}
    </ul>
  {% endif %}
  </div>
{% endblock %}

(modified from https://github.com/bashtage/sphinx-material/blob/0d31923e0fb08e85027c3e7f03d12673209872e3/sphinx_material/sphinx_material/search.html)

// that is, if you don't need the other place where jQuery is used AFAICS - version dropdown; could be replaced too I guess https://github.com/search?q=repo%3Abashtage%2Fsphinx-material%20%24(&type=code

ukusormus avatar Sep 23 '24 09:09 ukusormus