Skip to content

404 for search/search_index.json if search plugin disabled #1877

@aimeos

Description

@aimeos

I checked that...

  • ... the documentation does not mention anything about my problem
  • ... the problem doesn't occur with the default MkDocs template
  • ... the problem is not in any of my customizations (CSS, JS, template)
  • ... there are no open or closed issues that are related to my problem

Description

The service worker of the "search" plugin is executed even if the plugin is disabled using plugins: [] in the configuration. Thus, the service worker requests a none existing /search/search_index.json and a 404 is retured by the web server.

Expected behavior

The service worker isn't initialized if set plugins: [] in the configuration.

Actual behavior

Initialization is done unconditionally in the base.html file of the theme.

Steps to reproduce the bug

  1. Set plugins: [] in the configuration
  2. Open the docs in the browser
  3. In the browser console, an error about the missing search/search_index.json file is logged

Package versions

  • Python: Python 3.6.9
  • MkDocs: mkdocs, version 1.1.2
  • Material: Version: 4.5.0

Project configuration

plugins: []

Possible solution

Check if search plugin is enabled in base.html:

      {% if 'search' in plugins %}
        <script>
          app = initialize({
            base: "{{ base_url }}",
            features: {{ config.theme.features | tojson }},
            search: Object.assign({
              worker: "{{ 'assets/javascripts/worker/search.a68abb33.min.js' | url }}"
            }, typeof search !== "undefined" && search)
          })
        </script>
      {% endif %}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bugresolvedIssue is resolved, yet unreleased if open

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions