mirror of
https://github.com/Mintplex-Labs/anythingllm-embed.git
synced 2026-07-15 19:09:56 -04:00
[PR #16] [MERGED] fix: prevent streaming size jump from setext heading flicker #18
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Mintplex-Labs/anythingllm-embed/pull/16
Author: @gitofinho
Created: 5/7/2026
Status: ✅ Merged
Merged: 5/11/2026
Merged by: @timothycarambat
Base:
main← Head:fix/streaming-setext-flicker📝 Commits (2)
98de5bafix: prevent streaming size jump from setext heading flickera99117aremove useless tests📊 Changes
1 file changed (+12 additions, -2 deletions)
View changed files
📝
src/utils/chat/markdown.js(+12 -2)📄 Description
Refs Mintplex-Labs/anything-llm#5588
What
Disables
markdown-it's setext-heading rule (lheading) in the embed widget's chat renderer.Why
When the chat assistant streams a response, lines visibly jump in size for one frame whenever the model emits a hyphen-prefixed line (
text\n-). The line above briefly renders as an<h2>heading and reverts to a paragraph as soon as more content arrives. In responses with bullet lists this happens per bullet, so the chat text appears to repeatedly grow and shrink during streaming.Root cause:
lheading(setext) interpretstext\n-…as a heading the moment a single-lands on the next line; the next chunk reverts it. Token-by-token re-render viadangerouslySetInnerHTML(PromptReply/index.jsx) paints each transient frame. The widget'stailwind.config.jscorePlugins.preflight = falsesetting amplifies the visual jump because browser-default heading sizes leak through.Reproduction (current behavior on
main):After the patch,
Title\n-stays a paragraph until the rest of the bullet line arrives — no flip, no flicker.Behavior change scope
Limited to setext headings only:
Title\n===no longer renders as<h1>(renders as paragraph + literal===).Title\n---no longer renders as<h2>(renders as paragraph + horizontal rule once the third dash lands — same end state as a blank-line-separated---).# Header,## Section, …) is unchanged.In practice, current LLM outputs we have sampled use ATX headings exclusively — we have not observed setext output from any major model.
Tests
Added
scripts/streaming-render-spec.mjsplus atest:renderscript topackage.json. The spec asserts:Title\n-does NOT render as<h2>(setext flicker)Title\n---does NOT render as<h2>Title\n===does NOT render as<h1># Headerstill renders as<h1>Header</h1>(ATX must keep working)Plain Node, no new devDependencies. Run with
yarn test:render(ornode scripts/streaming-render-spec.mjs). The spec also includes a small drift sentinel that bails out if the production renderer's.disable(...)call no longer matches what the spec mirrors, so the two stay in sync.I went with this form because the repo currently has no
vitest/jestsetup, and bundling a full test framework into a 1-line bug fix felt heavier than appropriate. Happy to convert this to a propervitesttest (option a) or drop it entirely (option c) if you'd rather — I left option flags in #5588 and either path is a quick follow-up.Risk / rollout
src/utils/chat/markdown.js.Closes Mintplex-Labs/anything-llm#5588 once merged (cross-repo close — manual close may be needed).
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.