Skip to content

fix(mobile): polyfill Intl.PluralRules on Hermes - #5499

Merged
iscekic merged 2 commits into
mainfrom
fix/mobile-undefined-not-a-function
Aug 25, 2026
Merged

fix(mobile): polyfill Intl.PluralRules on Hermes#5499
iscekic merged 2 commits into
mainfrom
fix/mobile-undefined-not-a-function

Conversation

@iscekic

@iscekic iscekic commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes KILO-APP-5S: TestFlight build 1.0.6 (156) crashes at startup with Error: undefined is not a function.

  • Hermes ships without Intl.PluralRules. The FormatJS NumberFormat polyfill calls new Intl.PluralRules(...), so the first formatNumber call (tab accessibility labels in TabsLayout) threw.
  • Add @formatjs/intl-pluralrules and load it, with locale data, before the NumberFormat polyfill.
  • i18next also builds an Intl.PluralRules per language and caches the English one/other fallback when it is missing. Run prewarmIntl before changeLanguage at both call sites so the polyfill is in place first.
  • New test stubs the real Hermes Intl surface (Collator, DateTimeFormat, getCanonicalLocales only) and runs every formatter for all 87 languages plus i18next plural selection. It fails on main.

Hermes audit

Grepped apps/mobile/src and packages/app-shared for features Hermes lacks (structuredClone, Object.groupBy, Set methods, iterator helpers, toSorted, RegExp d/v flags, Intl.DisplayNames/Locale/Segmenter direct use). No other hits in app code. Every Intl constructor routes through intl-cache.ts.

Test plan

  • pnpm typecheck && pnpm lint && pnpm check:unused && pnpm test in apps/mobile
  • TestFlight build starts and shows the tabs

Fixes KILO-APP-5S

Hermes ships without Intl.PluralRules. The FormatJS NumberFormat polyfill
constructs one, so every formatNumber call on a device threw
"undefined is not a function" and the tabs layout crashed at startup.

Load the PluralRules polyfill and its locale data before the NumberFormat
polyfill. The Hermes test no longer stubs PluralRules as present.
@iscekic iscekic self-assigned this Aug 25, 2026
@kilo-code-bot

kilo-code-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • apps/mobile/src/app/_layout.tsx
  • apps/mobile/src/i18n/apply-language.ts
  • apps/mobile/src/lib/intl-cache-hermes-surface.test.ts
Previous Review Summary (commit 8927752)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 8927752)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (5 files)
  • apps/mobile/package.json
  • apps/mobile/src/lib/formatjs-locale-data.ts
  • apps/mobile/src/lib/intl-cache-hermes-numberformat.test.ts
  • apps/mobile/src/lib/intl-cache.ts
  • pnpm-lock.yaml

Reviewed by grok-4.6 · Input: 111.6K · Output: 15.6K · Cached: 525.6K

Review guidance: REVIEW.md from base branch main

i18next builds its own Intl.PluralRules per language and caches the
result. If the polyfill is not in place before the first render in the
new language, it caches the English one/other fallback for that language.

Run prewarmIntl before changeLanguage at both call sites. Add a test that
stubs the real Hermes Intl surface and exercises every formatter for
every supported language, plus i18next plural selection.
@iscekic
iscekic enabled auto-merge (squash) August 25, 2026 21:49
@iscekic
iscekic merged commit 60b55cc into main Aug 25, 2026
71 checks passed
@iscekic
iscekic deleted the fix/mobile-undefined-not-a-function branch August 25, 2026 21:50
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