Skip to content

Fix chat view hanging on messages with overlapping marks (#2280)#2309

Open
caddydove wants to merge 2 commits into
anyproto:developfrom
caddydove:fix/chat-overlapping-marks-hang
Open

Fix chat view hanging on messages with overlapping marks (#2280)#2309
caddydove wants to merge 2 commits into
anyproto:developfrom
caddydove:fix/chat-overlapping-marks-hang

Conversation

@caddydove

Copy link
Copy Markdown
Contributor

Description

Fixes #2280 — the chat view hangs when a message contains marks with touching/overlapping ranges (e.g. generated by MCP agents).

Root Cause

checkRanges in mark.ts merges adjacent marks of the same type and param to produce clean HTML. The merge condition used strict equality (prev.param == mark.param), which failed when one mark had param: undefined (omitted) and the other had param: '' (empty string). These marks were left unmerged, creating two separate tags wrapping adjacent ranges — which caused the chat view to hang during rendering.

Fix

Changed the param comparison in the merge condition to:

((prev.param || '') == (mark.param || ''))

This normalizes both undefined and '' to empty string, ensuring touching/overlapping same-type marks always merge correctly regardless of how the param was stored.

Test

Added a test case that verifies two adjacent italic marks (one with param: undefined, one with param: '') are merged into a single mark.

Verification

  • All 80 existing mark.test.ts tests pass
  • esbuild compilation succeeds

Replace require('linux-distro') with dynamic import() to resolve
TypeError: execa is not a function on Linux. linux-distro v4 is a
CJS module that internally requires execa, but execa v6+ is ESM-only.
require() cannot load ESM modules from CJS context, crashing the app
at the login screen. Dynamic import() handles CJS→ESM interop and
resolves the module correctly.

Fixes anyproto#2236
… checkRanges

checkRanges merges adjacent/overlapping marks of the same type and
param. However, the comparison (prev.param == mark.param) failed when
one mark had param: undefined and the other had param: '' — they were
treated as different and left unmerged. This caused the chat view to
hang when rendering messages with such marks (e.g. from MCP agents).

Fix: normalize the comparison with (prev.param || '') == (mark.param || '')
so undefined and empty string are treated equivalently, ensuring
touching/overlapping same-type marks are always merged.

Fixes anyproto#2280
@caddydove

Copy link
Copy Markdown
Contributor Author

Hi @requilence, this PR fixes #2280 — chat view hanging on messages with overlapping marks. The fix normalizes the param comparison in checkRanges so undefined and empty string are treated as equivalent, ensuring same-type marks always merge. Would appreciate a review when you have time. Thanks!

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.

Chat view hangs on some messages

1 participant