rust-lang / rust-lang/mdBook

If `!search_config.copy_js`, then perform useless search indexing, and search is disabled

Open
#2,403 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
22.2k
Forks
1.9k
PR merge metrics
PR metrics pending

Description

Problem

https://github.com/rust-lang/mdBook/blob/3bdcc0a5a6f3c85dd751350774261dbc357b02bd/src/renderer/html_handlebars/search.rs#L42-L54

Here, if !search_config.copy_js, then index is not used, so the above expensive computation is wasted.

More importantly, since the search index is not written, the search feature does not work.
That is, search is only enabled if search_config.enable && search_config.copy_js, instead of the intended behavior of just depending on search_config.enable.

Steps

N/A

Possible Solution(s)

The name copy_js seems to suggest the use of a CDN if set to false, however, looking at https://github.com/rust-lang/mdBook/blob/3bdcc0a5a6f3c85dd751350774261dbc357b02bd/src/theme/index.hbs#L311, the links to a CDN seems to be missing. If so, then the solution would be:

  1. Add the CDN links of the search JS to the index.hbs file and enable them when search_config.enable && !search_config.copy_js.
  2. Correct create_files to write the index JSON file when !search_config.copy_js.

However, if !search_config.copy_js disabling the search entirely is the intended behavior (which would be weird), then maybe we should just get rid of it and fully rely on search_config.enable.

Notes

Additionally, the search index is unnecessarily duplicated in both searchindex.json and searchindex.js, which are sequentially tentatively queried by searcher.js.

Version
Please see the permalink above pointing to the latest master as of this writing.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/renderer/html_handlebars/search.rs and inspect the referenced index.hbs and searcher.js paths to understand how copy_js, search_config.enable, and the two index files interact. Determine the intended behavior for copy_js=false, then verify that enabled search loads its assets and index without unnecessary indexing; confirm the generated files and search flow using the repository's existing checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, rust
Domain
search, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.