Skip to content

fix(search): save index even when some pages fail to load#2689

Open
Bowl42 wants to merge 4 commits intodocsifyjs:developfrom
Bowl42:fix/search-indexing-broken-links
Open

fix(search): save index even when some pages fail to load#2689
Bowl42 wants to merge 4 commits intodocsifyjs:developfrom
Bowl42:fix/search-indexing-broken-links

Conversation

@Bowl42
Copy link
Contributor

@Bowl42 Bowl42 commented Mar 4, 2026

Summary

  • Issue: When the search plugin indexes pages in auto mode, if any sidebar link returns a 404 (or any fetch error), the entire search index is lost. No search results are available — even for pages that loaded successfully.
  • Root cause: Docsify.get().then() in search.js has no rejection handler. When a fetch fails, count is never incremented for that path, so count never reaches len, and saveData() is never called.
  • Fix: Add an error handler callback to .then() that logs a warning and increments count, ensuring saveData() is called once all paths have been attempted.

Changes

src/plugins/search/search.js:

  • Added a second callback (error handler) to the .then() call, matching the custom ajax signature (_event, response)
  • Logs a console.warn with the failed path and HTTP status code (e.g. [Docsify] Failed to fetch /broken-page for search indexing (404)) for easier debugging
  • Increments count so that saveData() is still called when all fetches complete, preserving the index for pages that loaded successfully

Test plan

  • Set up a docsify site with search enabled and auto indexing
  • Add a broken link in the sidebar (pointing to a non-existent .md file)
  • Verify that search still works for all other pages
  • Verify a warning appears in the browser console for the failed fetch
  • Verify that search works normally when all links are valid (no regression)

Fixes #2674

🤖 Generated with Claude Code

When the search plugin indexes pages in auto mode, if any page fails to
load (e.g. 404), the fetch promise rejects with no error handler. This
means `count` never reaches `len`, so `saveData` is never called and the
entire search index is lost — even for pages that loaded successfully.

Add an error handler to the `.then()` call that still increments the
counter, ensuring the search index is saved with whatever pages were
successfully fetched.

Fixes docsifyjs#2674

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Mar 4, 2026

@Bowl42 is attempting to deploy a commit to the Docsify Team on Vercel.

A member of the Team first needs to authorize it.

Bowl42 and others added 3 commits March 4, 2026 21:11
Add console.warn so that failed fetches are visible in the developer
console, making it easier to debug missing search results.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The custom ajax `.then(success, error)` passes `(event, responseStatus)`
not a standard Error. Use the response status for a more useful warning
message, e.g. "(404)" instead of logging a ProgressEvent object.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@paulhibbitts
Copy link
Member

Hi @Bowl42 , thanks for the PR. Is this other PR not addressing the same core issue? #2675

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 this pull request may close these issues.

Search indexing does not work if some links are broken

2 participants