Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(i18n): keep the signed-in display name from being overwritten by the translation runtime

nirholas08587d3d91a9
diff --git a/public/nav-auth.js b/public/nav-auth.js
index d8dfbe113..347b361d8 100644
--- a/public/nav-auth.js
+++ b/public/nav-auth.js
@@ -61,7 +61,16 @@
if (el.dataset.authNameOriginal === undefined) {
el.dataset.authNameOriginal = el.textContent;
}
- el.textContent = authed && name ? name : el.dataset.authNameOriginal;
+ if (authed && name) {
+ el.textContent = name;
+ // Mark the element as personalized so the i18n runtime knows not to
+ // overwrite the display name with a translated label (the two systems
+ // otherwise race on the same text node, whoever runs last wins).
+ el.dataset.authNamed = '1';
+ } else {
+ el.textContent = el.dataset.authNameOriginal;
+ delete el.dataset.authNamed;
+ }
});
}
diff --git a/src/i18n.js b/src/i18n.js
index 861c9bd4a..9a8df20bb 100644
--- a/src/i18n.js
+++ b/src/i18n.js
@@ -79,7 +79,17 @@ export function applyCatalog(root, t) {
if (!root) return;
root.querySelectorAll?.('[data-i18n]').forEach((el) => {
const v = t(el.getAttribute('data-i18n'));
- if (v != null) el.textContent = v;
+ if (v == null) return;
+ // Some nav elements carry both data-i18n (a translatable label) and
+ // data-auth-name (their text is the signed-in visitor's display name). The
+ // name is not translatable copy and nav-auth owns it. Keep the translation
+ // as the signed-out fallback so a locale switch still localizes the label,
+ // but never clobber a live display name (data-auth-named === '1').
+ if (el.hasAttribute('data-auth-name')) {
+ el.dataset.authNameOriginal = v;
+ if (el.dataset.authNamed === '1') return;
+ }
+ el.textContent = v;
});
root.querySelectorAll?.('[data-i18n-html]').forEach((el) => {
const v = t(el.getAttribute('data-i18n-html'));
diff --git a/tests/i18n-nav-auth-cooperation.test.js b/tests/i18n-nav-auth-cooperation.test.js
new file mode 100644
index 000000000..6ad977d05
--- /dev/null
+++ b/tests/i18n-nav-auth-cooperation.test.js
@@ -0,0 +1,75 @@
+// @vitest-environment jsdom
+//
+// nav-auth and the i18n runtime both write to the text of the console pill: the
+// element carries data-auth-name (nav-auth swaps in the signed-in visitor's
+// display name) AND data-i18n (i18n swaps in a translated label). Whoever runs
+// last used to win, so on any annotated page the i18n pass clobbered the name
+// with "Dashboard" for signed-in users. These tests pin the cooperation: the
+// name is never a translatable string, but the label still localizes when
+// signed out.
+
+import { describe, it, expect, beforeEach } from 'vitest';
+import { applyCatalog } from '../src/i18n.js';
+import navAuth from '../public/nav-auth.js';
+
+const { applyAuthState } = navAuth;
+
+// A catalog function like the runtime's `t`: maps the pill key to a localized
+// label, everything else passes through unchanged.
+const es = (key) => (key === 'nav.console' ? 'Panel →' : key);
+
+function pill() {
+ document.body.innerHTML =
+ '<a class="console" data-auth-name data-i18n="nav.console">Dashboard →</a>';
+ return document.querySelector('.console');
+}
+
+describe('nav-auth ⇄ i18n cooperation on a shared element', () => {
+ beforeEach(() => {
+ document.body.innerHTML = '';
+ });
+
+ it('i18n does not clobber a live display name (the regression)', () => {
+ const el = pill();
+ applyAuthState(document, true, 'Catherine Maerial');
+ expect(el.textContent).toBe('Catherine Maerial');
+ // i18n runs afterward (its catalog fetch resolves late); name must survive.
+ applyCatalog(document, es);
+ expect(el.textContent).toBe('Catherine Maerial');
+ // The translation is retained as the signed-out fallback.
+ expect(el.dataset.authNameOriginal).toBe('Panel →');
+ });
+
+ it('signed-out visitor still gets the translated label', () => {
+ const el = pill();
+ applyCatalog(document, es);
+ expect(el.textContent).toBe('Panel →');
+ applyAuthState(document, false, null);
+ expect(el.textContent).toBe('Panel →');
+ });
+
+ it('converges regardless of which runtime paints first', () => {
+ // i18n first, then auth.
+ let el = pill();
+ applyCatalog(document, es);
+ applyAuthState(document, true, 'Ada');
+ expect(el.textContent).toBe('Ada');
+
+ // auth first, then i18n.
+ el = pill();
+ applyAuthState(document, true, 'Ada');
+ applyCatalog(document, es);
+ expect(el.textContent).toBe('Ada');
+ });
+
+ it('a runtime locale switch keeps the name and refreshes the fallback', () => {
+ const el = pill();
+ applyAuthState(document, true, 'Grace');
+ applyCatalog(document, es); // switch to Spanish
+ expect(el.textContent).toBe('Grace');
+ expect(el.dataset.authNameOriginal).toBe('Panel →');
+ // Sign out now → the localized label, not the stale English original.
+ applyAuthState(document, false, null);
+ expect(el.textContent).toBe('Panel →');
+ });
+});