Skip to content

feat(chat): support render empty prompt #575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mortalYoung
Copy link
Collaborator

变更类型

请选择以下选项以描述 PR 的类型:

  • Bug 修复(修复现有问题)
  • 新功能(添加了一个功能)
  • 代码优化(性能改进、代码重构)
  • 文档更新
  • 单测新增或修改
  • 其他(请说明):

相关问题

变更内容

  • 优化提问为空的 Prompt 渲染
  • 优化 react-markdown 的渲染,避免 validateDOMNesting 问题

详细描述

对应 Previewer

@mortalYoung mortalYoung requested review from Copilot and LuckyFBB June 17, 2025 02:47
Copy link

@Copilot 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 introduces a new feature to support rendering an empty prompt and optimizes the rendering behavior for both typing effects and markdown content, particularly to avoid HTML splitting and validateDOMNesting issues.

  • Introduces a helper function in the typing effect to ensure HTML tags aren’t split.
  • Adds a guard to the prompt component to return null when no title is provided.
  • Modifies the markdown rendering to conditionally use a div element to prevent DOM nesting errors.

Reviewed Changes

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

File Description
src/useTyping/index.ts Adds a helper function to calculate the next chunk position without splitting HTML tags.
src/chat/prompt/index.tsx Returns null for empty prompts based on a missing title field.
src/chat/markdown/index.tsx Adjusts paragraph rendering to avoid validateDOMNesting errors with non-text children.
Comments suppressed due to low confidence (2)

src/chat/prompt/index.tsx:31

  • [nitpick] Consider adding a comment here to clarify why the component returns null when 'data.title' is missing, helping maintain readability and understandability of the logic.
if (!data?.title) return null;

src/chat/markdown/index.tsx:51

  • [nitpick] While the conditional rendering prevents validateDOMNesting errors, verify that using a
    instead of a

    for mixed content does not affect the intended semantics or accessibility of the output.

p: (data) => {

function getNextChunkPosition() {
const rest = queue.current.slice(beginIndex.current);
const chunk = rest.slice(0, typingCountOnTime.current);
const validHTMLTagRegex = /<[a-zA-Z]{0,4}\s[^<]*>/;
Copy link
Preview

Copilot AI Jun 17, 2025

Choose a reason for hiding this comment

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

The regex limits tag names to a maximum of 4 letters, which may not cover standard HTML tags longer than 4 characters (e.g., 'section' or 'article'). Consider using a more general pattern such as /<[a-zA-Z]+\b[^>]*>/ to ensure all valid tags are correctly handled.

Suggested change
const validHTMLTagRegex = /<[a-zA-Z]{0,4}\s[^<]*>/;
const validHTMLTagRegex = /<[a-zA-Z]+\b[^>]*>/;

Copilot uses AI. Check for mistakes.

@mortalYoung mortalYoung changed the title WIP: feat(chat): support render empty prompt feat(chat): support render empty prompt Jun 17, 2025
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