[PR #8670] [MERGED] test(chat): guard speaker-tag boundary rerenders against duplicated words #8736

Closed
opened 2026-11-07 17:39:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8670
Author: @SpicyMarinara
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/speaker-tag-keys-8661


📝 Commits (1)

  • f2dbf4f test(chat): guard speaker-tag boundary rerenders against duplicated words (#8661)

📊 Changes

1 file changed (+44 additions, -0 deletions)

View changed files

📝 e2e/chat-widget-dialogue-colors.e2e.ts (+44 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #8661

Why this change

  • #8661 reports message text that renders twice or out of place after a post-processing agent rewrites only a reply's <speaker> tags. The reporter is on v2.5.1, built from main.
  • The cause is in renderWithSpeakerTags() in ChatMessage.tsx on main. Each narration chunk's highlightDialogue() output was spread into one children list. Every call restarts its key counter, so two narration chunks that both quote someone each produce a <strong key="d0">. When the speaker boundaries move, React matches up the wrong nodes and words show twice until the message remounts.
  • Staging already fixed this in #8632 (commit 6d96cf9195), which wraps each narration chunk in its own keyed Fragment. That fix hasn't reached main yet. This PR adds the missing regression for the issue's exact scenario. It doesn't change any production code.

What changed

  • e2e/chat-widget-dialogue-colors.e2e.ts: new test, "Roleplay speaker-tag boundary changes rerender the same words".
    • It sets up a merged roleplay chat with one message and two swipes: the same words, with different <speaker> boundaries. Before: Alpha "One" <speaker=Bram>*Beta*</speaker> "Two" Gamma. After: <speaker=Bram>Alpha "One"</speaker> *Beta* <speaker=Ada>"Two" Gamma</speaker>.
    • It switches between the two three times in place, without remounting.
    • It checks that the text is exactly Alpha "One" Beta "Two" Gamma, that the speaker colors moved, and that React logged no duplicate-key warning.
  • With #8632's change reverse-applied (the main code), the test fails with the reported doubling: "One"Alpha "One" Beta "Two" Gamma. On staging it passes.
  • I also checked every other renderer in the same path for the same key collision: markdown blocks, name colors, mentions, custom emoji, Mari's links and the Game journal. All of them prefix their keys or put their nodes in a nested scope.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

What the agent ran locally:

  • node ./scripts/pnpm-runner.mjs check and check:e2e-types pass.
  • e2e/chat-widget-dialogue-colors.e2e.ts and e2e/roleplay-vn.e2e.ts pass on desktop-chromium (29/29). The new test and #8632's speaker-tag swipe tests pass on mobile-chromium and mobile-webkit (6/6).
  • Regressions markdown-code, chat-message-css-security, persona-card-dialogue, chat-sweep and issue-sweep-chat pass.
  • Local CodeRabbit raised one trivial suggestion, rejected: also assert that the italic Beta inside Bram's tag takes Bram's color. Tried in the test, it fails because narration inside a speaker tag keeps the normal text color (rgb(212, 212, 212)); only quoted dialogue is colored, which the One/Two checks already cover.
  • An independent review agent confirmed that the test fails on the main code and that its duplicate-key check catches React's warning. It found no defects.

For a human to verify:

  • On staging, in a merged-mode group roleplay chat with group speaker colors on, let a post-processing agent rewrite only a reply's <speaker> boundaries. Manually verify that the message shows each word once and recolors immediately.
  • Users on v2.5.1 keep seeing #8661 until staging is promoted to main.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

No docs change: test only.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/8670 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/speaker-tag-keys-8661` --- ### 📝 Commits (1) - [`f2dbf4f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f2dbf4fff367ccf67f964a43c4416898fcf7076f) test(chat): guard speaker-tag boundary rerenders against duplicated words (#8661) ### 📊 Changes **1 file changed** (+44 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `e2e/chat-widget-dialogue-colors.e2e.ts` (+44 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #8661 ## Why this change - #8661 reports message text that renders twice or out of place after a post-processing agent rewrites only a reply's `<speaker>` tags. The reporter is on v2.5.1, built from `main`. - The cause is in `renderWithSpeakerTags()` in `ChatMessage.tsx` on `main`. Each narration chunk's `highlightDialogue()` output was spread into one children list. Every call restarts its key counter, so two narration chunks that both quote someone each produce a `<strong key="d0">`. When the speaker boundaries move, React matches up the wrong nodes and words show twice until the message remounts. - **Staging already fixed this** in #8632 (commit 6d96cf9195), which wraps each narration chunk in its own keyed Fragment. That fix hasn't reached `main` yet. This PR adds the missing regression for the issue's exact scenario. It doesn't change any production code. ## What changed - `e2e/chat-widget-dialogue-colors.e2e.ts`: new test, "Roleplay speaker-tag boundary changes rerender the same words". - It sets up a merged roleplay chat with one message and two swipes: the same words, with different `<speaker>` boundaries. Before: `Alpha "One" <speaker=Bram>*Beta*</speaker> "Two" Gamma`. After: `<speaker=Bram>Alpha "One"</speaker> *Beta* <speaker=Ada>"Two" Gamma</speaker>`. - It switches between the two three times in place, without remounting. - It checks that the text is exactly `Alpha "One" Beta "Two" Gamma`, that the speaker colors moved, and that React logged no duplicate-key warning. - With #8632's change reverse-applied (the `main` code), the test fails with the reported doubling: `"One"Alpha "One" Beta "Two" Gamma`. On staging it passes. - I also checked every other renderer in the same path for the same key collision: markdown blocks, name colors, mentions, custom emoji, Mari's links and the Game journal. All of them prefix their keys or put their nodes in a nested scope. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes What the agent ran locally: - `node ./scripts/pnpm-runner.mjs check` and `check:e2e-types` pass. - `e2e/chat-widget-dialogue-colors.e2e.ts` and `e2e/roleplay-vn.e2e.ts` pass on desktop-chromium (29/29). The new test and #8632's speaker-tag swipe tests pass on mobile-chromium and mobile-webkit (6/6). - Regressions markdown-code, chat-message-css-security, persona-card-dialogue, chat-sweep and issue-sweep-chat pass. - Local CodeRabbit raised one trivial suggestion, rejected: also assert that the italic `Beta` inside Bram's tag takes Bram's color. Tried in the test, it fails because narration inside a speaker tag keeps the normal text color (`rgb(212, 212, 212)`); only quoted dialogue is colored, which the `One`/`Two` checks already cover. - An independent review agent confirmed that the test fails on the `main` code and that its duplicate-key check catches React's warning. It found no defects. For a human to verify: - On staging, in a merged-mode group roleplay chat with group speaker colors on, let a post-processing agent rewrite only a reply's `<speaker>` boundaries. Manually verify that the message shows each word once and recolors immediately. - Users on v2.5.1 keep seeing #8661 until staging is promoted to `main`. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) No docs change: test only. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:39:21 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#8736
No description provided.