Skip to content

fix(element): don't render previous locale's text with the new font (#3043)#8927

Merged
willeastcott merged 2 commits into
mainfrom
fix-i18n-prev-locale-char-warning
Jun 18, 2026
Merged

fix(element): don't render previous locale's text with the new font (#3043)#8927
willeastcott merged 2 commits into
mainfrom
fix-i18n-prev-locale-char-warning

Conversation

@willeastcott

Copy link
Copy Markdown
Contributor

Fixes #3043

Problem

On a locale change a localized Text Element updates its font and its text from two separate i18n change handlers. The font handler (LocalizedAsset, bound in the constructor) runs before the text handler (TextElement._onLocaleSet, bound in onEnable). When the new locale's font is already cached, its load fires synchronously and the new font is rendered with the previous locale's string before the text is updated — emitting spurious Character 'X' is missing warnings for the old language. When the font isn't cached the swap is async, so the bug only shows intermittently.

Fix

Refresh the localized text in _onFontLoad before applying the font, so the new font is never rendered with the previous locale's string. No-op for non-localized elements and for the async path.

Testing

  • Added a regression test (text-element.test.mjs) that fails without the fix and passes with it; full suite green.
  • Verified end-to-end against the forum repro project (cycling all 6 languages with fonts cached): warnings drop from many-per-switch to zero, text and font correct at every step.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

Build size report

This PR changes the size of the minified bundles.

Bundle Minified Gzip Brotli
playcanvas.min.js 2275.7 KB (+0.1 KB, +0.00%) 584.4 KB (+0.0 KB, +0.00%) 454.1 KB (−0.1 KB, −0.02%)
playcanvas.min.mjs 2273.1 KB (+0.1 KB, +0.00%) 583.5 KB (+0.0 KB, +0.00%) 453.7 KB (−0.1 KB, −0.03%)

…3043)

On a locale change the localized font and the localized text are updated
by two separate handlers. When the new font is already cached its load
fires synchronously, before the text handler runs, so the new font is
briefly rendered with the previous locale's string - emitting spurious
"character is missing" warnings. Refresh the localized text in
_onFontLoad before applying the font so the two never mismatch.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@willeastcott willeastcott self-assigned this Jun 18, 2026
@willeastcott willeastcott added the area: ui UI related issue label Jun 18, 2026
@willeastcott willeastcott merged commit 1fd2add into main Jun 18, 2026
10 checks passed
@willeastcott willeastcott deleted the fix-i18n-prev-locale-char-warning branch June 18, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ui UI related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'Character X is missing' warning is showing up for the previous language when switching

1 participant