Skip to content

fix: gracefully handle page loading failures during search indexing#2675

Open
kokovtsev wants to merge 1 commit intodocsifyjs:developfrom
kokovtsev:fix/search-indexing-404
Open

fix: gracefully handle page loading failures during search indexing#2675
kokovtsev wants to merge 1 commit intodocsifyjs:developfrom
kokovtsev:fix/search-indexing-404

Conversation

@kokovtsev
Copy link

Summary

Gracefully handle page loading failures during the search indexing processing.

Before this fix, the loaded page counter was incremented only in the successful branch of Docsify.get, so if any request failed then the counter never reached the expected value and saveData was never called.

Related issue, if any:

Fixes #2674

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

For any code change,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed

Does this PR introduce a breaking change?

  • Yes
  • No

Tested in the following browsers:

  • Chrome
  • Firefox
  • Safari
  • Edge

@vercel
Copy link

vercel bot commented Feb 5, 2026

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

A member of the Team first needs to authorize it.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical bug in the search plugin where indexing fails completely if any page linked in the sidebar fails to load. The fix ensures that the search index is saved with successfully loaded pages even when some pages fail to load, allowing users to search through available content.

Changes:

  • Added error handler to Docsify.get promise to increment the counter even when page loading fails
  • Extracted counter increment logic into a saveIfCompleted helper function that is called in both success and error paths
  • Added comprehensive e2e test to verify search works when some pages fail to load

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/plugins/search/search.js Adds error handler for failed page loads and refactors counter logic to ensure saveData is called even when some pages fail
test/e2e/search.test.js Adds test case that verifies search functionality works when a broken page link is present in the sidebar

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

vm.router,
config.depth,
indexKey,
);
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The try-finally block will not catch errors thrown by genIndex. If genIndex throws an error (e.g., if window.marked.lexer fails or other processing errors occur), the error will propagate as an unhandled promise rejection. This should be a try-catch-finally block instead, with the catch block logging the error similar to how fetch errors are handled in the rejection handler below (lines 351-359). The catch block should log a warning message like "Search plugin: failed to generate index for file" and then the finally block should call saveIfCompleted to ensure indexing completes for other pages.

Suggested change
);
);
} catch (err) {
// eslint-disable-next-line no-console
console.warn(
'Search plugin: failed to generate index for file',
path,
err,
);

Copilot uses AI. Check for mistakes.
@vercel
Copy link

vercel bot commented Feb 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docsify-preview Ready Ready Preview, Comment Feb 26, 2026 3:45am

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