-
Notifications
You must be signed in to change notification settings - Fork 842
AI Search: Prevent DOM errors when asking AI Chat questions #46476
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
base: trunk
Are you sure you want to change the base?
Conversation
The AI Chat component would crash with a React DOM reconciliation error
("removeChild") after submitting multiple questions. The root cause was
a raw text node (the loading message) that React couldn't reliably manage
when external scripts might modify the DOM.
Fixed by:
- Wrapping the loading message in <span> tags for stable DOM management
- Stripping HTML during word-by-word animation to avoid invalid fragments
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
There was a problem hiding this 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 DOM reconciliation errors in the AI Chat feature by preventing invalid HTML fragments during word-by-word animation. The fix strips HTML tags to plain text during animation, then displays the full HTML after animation completes, and wraps the loading message in a <span> element for proper DOM management.
Key Changes:
- Modified the
ShowLittleByLittlecomponent to strip HTML tags during animation and display plain text word-by-word - Wrapped the loading message in a
<span>tag to prevent DOM errors - Improved code comments to clarify the new animation approach
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
projects/plugins/jetpack/extensions/blocks/ai-chat/question-answer.js |
Refactored animation logic to strip HTML during word-by-word display, wrapped loading message in span, and updated comments |
projects/plugins/jetpack/changelog/fix-ai-search-disappearing |
Added changelog entry documenting the bugfix |
projects/plugins/jetpack/extensions/blocks/ai-chat/question-answer.js
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/blocks/ai-chat/question-answer.js
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/blocks/ai-chat/question-answer.js
Outdated
Show resolved
Hide resolved
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 Full summary · PHP report · JS report Coverage check overridden by
Coverage tests to be added later
|
We just needed the span tag
kangzj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! Thanks for the fix 👍
Fixes SEARCH-113
Proposed changes:
This PR wraps AI's loading message in a
<span>tag for more reliable DOM management.Other information:
Jetpack product discussion
No
Does this pull request change what data or activity we track or use?
No
Testing instructions:
removeChild,<Text>, or relatedconsoleerrors.