Skip to content

Comments

fix: 不将全量数据在一开始就给Bot#254

Merged
longsizhuo merged 2 commits intomainfrom
fix/build_too_long
Feb 19, 2026
Merged

fix: 不将全量数据在一开始就给Bot#254
longsizhuo merged 2 commits intomainfrom
fix/build_too_long

Conversation

@longsizhuo
Copy link
Member

之前的流程:

  1. 用户 打开一篇 5 万字的文档页面。
  2. Next.js 后端 渲染页面组件 (page.tsx)。
  3. 这时就 立刻 把这 5 万字读出来,塞进了 组件的 props 里。
  4. 浏览器 收到 HTML。这 5 万字被完整地复制了一份,包含在 HTML 源代码的 NEXT_DATA JSON 里(这就好比你为了吃一个汉堡,把整头牛牵进了餐厅)。
  5. 就算用户永远不点开右下角的 AI 对话框,这 5 万字的数据也已经下载到他的手机/电脑里了。

现在的流程是:

  1. 用户 打开页面。我们只传了个 ID(slug: "deploy")。HTML 很轻,下载很快。
  2. 用户 读完觉得不懂,点开 AI 说:“这步怎么做?”
  3. 浏览器 发送请求给后端:“我要问问题,这是文档 ID。”
  4. API 后端 收到请求,这时候才去硬盘里把这 5 万字读出来,喂给 AI 模型。

经过本地pnpm dev 初步测试,build阶段会比之前快很多

@longsizhuo longsizhuo self-assigned this Feb 18, 2026
@longsizhuo longsizhuo added the enhancement New feature or request label Feb 18, 2026
@vercel
Copy link

vercel bot commented Feb 18, 2026

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

Project Deployment Actions Updated (UTC)
involutionhell-github-io Ready Ready Preview, Comment Feb 18, 2026 3:57pm
website-preview Ready Ready Preview, Comment Feb 18, 2026 3:57pm

Copy link
Contributor

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 optimizes the documentation page loading performance by deferring the extraction and transmission of full document content until the AI assistant is actually invoked. Previously, all document content (up to 50,000 characters) was extracted and embedded in the initial HTML payload regardless of whether users interacted with the AI assistant. Now, only the document slug is passed initially, and content is fetched on-demand via the API route when users engage with the chat feature.

Changes:

  • Removed server-side content extraction logic from the docs page component
  • Moved the extractTextFromMDX function from page.tsx to the API chat route
  • Modified the chat API to fetch and process document content on-demand when a slug is provided

Reviewed changes

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

File Description
app/docs/[...slug]/page.tsx Removed content extraction logic and eliminated the content field from pageContext
app/components/DocsAssistant.tsx Removed content field from the PageContext interface
app/api/chat/route.ts Added on-demand content fetching logic and moved the extractTextFromMDX helper function here
Comments suppressed due to low confidence (1)

app/docs/[...slug]/page.tsx:1

  • Corrected 'client/page side' to 'server/page side' since Next.js page components run on the server, not the client.

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

Comment on lines +51 to +52
if (page) {
const fullFilePath = path.join(process.cwd(), "app/docs", page.path);
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

The path construction uses page.path directly, but based on the original code it should use page.file.path to match the previous implementation in page.tsx.

Suggested change
if (page) {
const fullFilePath = path.join(process.cwd(), "app/docs", page.path);
if (page && page.file?.path) {
const fullFilePath = path.join(
process.cwd(),
"app/docs",
page.file.path,
);

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

这是老用法,file是deprecated

@longsizhuo longsizhuo merged commit ae69996 into main Feb 19, 2026
8 checks passed
@longsizhuo
Copy link
Member Author

@Crokily 我先Merge了,有什么问题再在这个基础上改吧。我得先去看看 #131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant