Skip to content

fix: 修复新建聊天时模型硬编码问题,并修复新建聊天时,第一天信息输出完成之后页面回闪的问题#297

Merged
xun082 merged 1 commit intomainfrom
fix/chat-ai-new-chat-model-error
Feb 10, 2026
Merged

fix: 修复新建聊天时模型硬编码问题,并修复新建聊天时,第一天信息输出完成之后页面回闪的问题#297
xun082 merged 1 commit intomainfrom
fix/chat-ai-new-chat-model-error

Conversation

@xun082
Copy link
Copy Markdown
Owner

@xun082 xun082 commented Feb 10, 2026

PR 描述

PR 类型

  • 🐛 Bug 修复
  • ✨ 新功能
  • 💄 UI/UX 改进
  • ♻️ 重构
  • 🚀 性能优化
  • 📝 文档更新
  • 🔄 其他

Issue 关联

Closes #

其他信息

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 10, 2026

Deploy Preview for ornate-blancmange-89db6b failed. Why did it fail? →

Name Link
🔨 Latest commit a1860c6
🔍 Latest deploy log https://app.netlify.com/projects/ornate-blancmange-89db6b/deploys/698ad8d4f2b53e000867f17a

@xun082 xun082 merged commit 3558f81 into main Feb 10, 2026
0 of 6 checks passed
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @xun082, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求主要解决了聊天功能中的两个关键问题:一是移除了新建聊天时对模型选项的硬编码,使得模型选择更加灵活和动态;二是优化了新会话创建后页面 URL 更新的机制,避免了用户在接收到第一条消息后页面出现不必要的闪烁。这些改进提升了用户体验,并使系统能够更好地适应未来模型列表的变更。

Highlights

  • 模型配置动态化: 修复了新建聊天时模型硬编码的问题,现在模型列表将从后端动态获取,提高了系统的灵活性和可维护性。
  • 页面闪烁问题修复: 解决了新建聊天时,第一条信息输出完成后页面 URL 更新导致页面回闪的视觉问题,提升了用户体验。
  • 模型配置初始化优化: 优化了模型配置的初始化和恢复逻辑,确保在模型列表加载完成后,能正确地从 sessionStorage 恢复配置或选择默认模型。
  • Vite 构建配置更新: 更新了部分包的 Vite 构建配置,禁用了 rollupTypes 并启用了 staticImport,以解决潜在的类型打包问题。
Changelog
  • apps/DocFlow/src/app/chat-ai/[id]/page.tsx
    • 将新会话 URL 同步逻辑中的 router.replace 替换为 window.history.replaceState,以避免在 URL 更新时触发组件重新挂载,从而解决页面闪烁问题。
    • 调整了 useEffect 的依赖项,使其更精确,以避免不必要的副作用执行。
  • apps/DocFlow/src/app/chat-ai/_components/ChatAIPanels.tsx
    • 移除了对 MODEL_OPTIONS 常量的导入和使用,现在模型显示名称完全依赖于动态获取的模型列表。
  • apps/DocFlow/src/app/chat-ai/_components/ChatInterface.tsx
    • 重构了模型配置的初始化逻辑,引入 isConfigInitialized 状态,确保在模型列表加载完成且配置初始化后才执行输入初始化。
    • 更新了从 sessionStorage 恢复模型配置的逻辑,使其能正确处理动态模型列表,并确保选择的模型有效。
    • 移除了旧的、基于静态模型列表的模型自动选择策略。
  • apps/DocFlow/src/app/chat-ai/_components/ConfigFields.tsx
    • 移除了对 useEffectMODEL_OPTIONS 的导入,简化了组件逻辑。
    • 更新了模型选择下拉菜单,使其在模型加载时显示“加载模型中...”的占位符,并在模型列表为空或加载中时禁用选择。
    • 现在模型选项完全来源于 useChatModels 钩子动态获取的模型列表。
  • apps/DocFlow/src/app/chat-ai/constants.ts
    • 移除了 MODEL_OPTIONS 常量定义,将模型列表的来源完全交给后端。
    • DEFAULT_MODEL_CONFIG 中的 modelName 默认值设置为空字符串,以便在运行时动态设置第一个可用模型。
  • packages/alert/vite.config.ts
    • 修改了 Vite 构建配置,将 rollupTypes 设置为 false,并添加 staticImport: true,以解决 API Extractor 路径问题。
  • packages/bilibili/vite.config.ts
    • 修改了 Vite 构建配置,将 rollupTypes 设置为 false,并添加 staticImport: true,以解决 API Extractor 路径问题。
Activity
  • 目前没有发现人工活动。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

这次的 PR 同时解决了两个问题:新建聊天时的模型硬编码,以及新会话首条消息返回后页面回闪。对于模型硬编码问题,通过从后端动态加载模型列表,并以此为基础进行配置初始化和验证,彻底移除了前端的硬编码,做得很好。对于页面回闪问题,使用 window.history.replaceState 替代 router.replace 来更新 URL,避免了不必要的页面重载和组件重挂载,是正确的修复方式。代码整体重构得不错,将模型初始化的逻辑统一处理,提高了代码的可维护性。我只有一个关于错误处理的小建议,以增强代码的可调试性。

Comment on lines +126 to +130
try {
savedConfig = JSON.parse(saved) as Partial<ModelConfig>;
} catch {
// 解析失败,使用默认
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

这个 catch 块是空的。虽然代码能够优雅地回退到默认行为,但完全“吞掉”错误会给调试带来困难,特别是当 sessionStorage 中存在格式不正确的数据时。建议将错误信息打印到控制台,以方便追踪问题。

        try {
          savedConfig = JSON.parse(saved) as Partial<ModelConfig>;
        } catch (e) {
          console.error('Failed to parse chat_model_config from sessionStorage:', e);
          // 解析失败,使用默认
        }

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.

1 participant