Skip to content

fix(chat): preserve session title against i18n MutationObserver overwrite#74

Merged
xaspx merged 1 commit into
xaspx:mainfrom
tomekpanek:fix/chat-title-i18n-overwrite
Jun 4, 2026
Merged

fix(chat): preserve session title against i18n MutationObserver overwrite#74
xaspx merged 1 commit into
xaspx:mainfrom
tomekpanek:fix/chat-title-i18n-overwrite

Conversation

@tomekpanek

Copy link
Copy Markdown
Contributor

Symptom

Click any historical session in the sidebar. The chat header briefly shows the saved title (e.g. "Polish Hello to Tomek"), then instantly flips back to "New Chat". Sending a message in that session works correctly (it routes to the right session), but the header stays stuck on "New Chat".

Affects every loaded session, every time. Also affects rename — typing a new title via the rename modal flashes the new value and reverts.

Root cause

<div class="chat-title" id="chat-title" data-i18n="auto.newChat2">New Chat</div> carries the data-i18n attribute. main.js installs a debounced MutationObserver that runs applyTranslations() on any DOM mutation — and applyTranslations reads data-i18n and overwrites textContent to the localized value of auto.newChat2.

Flow:

  1. loadChatSession() sets titleEl.textContent = sessionTitle
  2. Mutation observer fires from the textContent change
  3. applyTranslations() finds data-i18n="auto.newChat2" still on the element
  4. It overwrites textContent back to "New Chat"

The session title is correct in memory (state._currentChatSession) and in the DB — only the header display is wrong.

Fix

Four sites need to manage data-i18n when changing the title:

Site Action
loadChatSession — bind session title removeAttribute('data-i18n') after setting textContent
newChatSession — reset to "New Chat" setAttribute('data-i18n', 'auto.newChat2') so future locale switches still pick it up
Rename flow (renameChatSession) removeAttribute('data-i18n') after setting new title
updateChatHeader both branches — remove attr in the has-sid branch, restore in the no-sid branch

After the fix, the observer still runs but only finds data-i18n when the title is genuinely the i18n-managed "New Chat" placeholder. Real session titles are immune.

Test plan

  • Click a historical session in the sidebar → its title shows and stays
  • Click "+ New Chat" → header reverts to "New Chat"
  • Switch UI language (Polish ↔ English) on a New Chat → label re-translates
  • Switch UI language while a real session is open → its title does not get clobbered
  • Rename a session via the modal → new title sticks, no flash-back

Verified

Tested on top of main (204e0e5, v3.6.0). Deterministic repro before, gone after.

@xaspx xaspx merged commit 264c26b into xaspx:main Jun 4, 2026
0 of 3 checks passed
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.

2 participants