perf(core): skip search index generation when search is disabled#3031
Merged
perf(core): skip search index generation when search is disabled#3031
Conversation
## 修改内容
### 1. `packages/core/src/node/route/extractPageData.ts`
- 在 `ExtractPageDataOptions` 接口中添加了 `searchEnabled?: boolean` 选项
- 在 `getPageIndexInfoByRoute` 函数中:
- 解构获取 `searchEnabled`(默认为 `true`)
- 当 `searchEnabled` 为 `false` 时,跳过以下搜索索引相关的处理:
- 跳过运行 processor 插件生成搜索内容
- 跳过计算 TOC 的 `charIndex`(设为 -1)
- 返回空的 `content` 字段
- 仍然保留必要的信息:title、toc(无 charIndex)、description、frontmatter 等
### 2. `packages/core/src/node/runtimeModule/pageData/createPageData.ts`
- 从 `userConfig?.search` 获取搜索配置
- 判断 `searchEnabled = searchConfig !== false`
- 修复了 `searchCodeBlocks` 的判断逻辑,确保在 `searchConfig` 为 `false` 时不会出错
- 将 `searchEnabled` 传递给 `extractPageData`
## 优化效果
当配置 `search: false` 时:
- 跳过 markdown 内容的处理和转换(`processor.run` 和 `processor.stringify`)
- 跳过 TOC charIndex 的计算逻辑
- 返回空的 `content`,减少内存占用
- 保留基本的页面元数据(title、toc、frontmatter 等)供其他功能使用
✅ Deploy Preview for rspress-v2 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
Rsdoctor Bundle Diff AnalysisFound 3 projects in monorepo, 1 project with changes. 📊 Quick Summary
📋 Detailed Reports (Click to expand)📁 webPath:
📦 Download Diff Report: web Bundle Diff Generated by Rsdoctor GitHub Action |
Timeless0911
approved these changes
Jan 20, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
该 PR 旨在在用户配置 search: false 时,减少/跳过搜索索引相关内容的生成开销(将跳过搜索内容的处理与 stringify)。
Changes:
- 在
createPageData中识别search: false并透传searchEnabled到extractPageData - 在
extractPageData/getPageIndexInfoByRoute中新增searchEnabled选项,并在关闭时提前返回,避免生成搜索用的content
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/core/src/node/runtimeModule/pageData/createPageData.ts | 解析 search 配置并新增 searchEnabled,传入页面数据提取流程 |
| packages/core/src/node/route/extractPageData.ts | 新增 searchEnabled 参数;关闭搜索时跳过搜索索引内容生成(processor.run/stringify) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Optimize build performance by skipping search index content generation when
search: falseis configured.Related Issue
Checklist
AI Summary
What changes were made
Added
searchEnabledoption toExtractPageDataOptionsinextractPageData.tsModified
getPageIndexInfoByRoutefunction inextractPageData.tssearchEnabledisfalse, the function now returns early with:contentfield (no search content generated)charIndex: -1(skip character index calculation)processor.run()andprocessor.stringify()Updated
createPageDatafunction increatePageData.tssearchEnabledbased on whethersearchconfig isfalsesearchCodeBlockslogic to properly handle whensearchConfigisfalsesearchEnabledtoextractPageDataWhy these changes were made
When users configure
search: falsein their Rspress config (e.g., when using external search solutions like Algolia), the build process was still performing unnecessary work to generate search index content. This optimization:Implementation details
extractPageData.tssearchEnabled: true) is preserved for backward compatibilityThis PR was written using Vibe Kanban