Skip to content

fix(ui): renew t when a topic lands and follow only the shown language - #5084

Closed
tale-code-bot wants to merge 4 commits into
mainfrom
fix/i18n-topic-landing-follow
Closed

tale-code-bot wants to merge 4 commits into
mainfrom
fix/i18n-topic-landing-follow

Conversation

@tale-code-bot

Copy link
Copy Markdown
Collaborator

Fixes the two per-topic message loading defects in packages/ui that #4433 found in the post-merge review of c90f244a9e / 8b750caf30.

Task: TALE-78 (Development board). The plan is on the task.

A. A topic that lands late leaves memoised labels in English

Root cause: useT cached one t per language and namespace (readers.fixed). A landing re-rendered the namespace's readers, but they got the same t, so useMemo(…, [t]) kept the fallback. Example: the granularity and metric options of the usage page.

Fix:

  • The shared t now belongs to the reader's snapshot (language + landings of its namespace). Every reader of a namespace still gets the same t across renders, and a new one when the language changes or its words land.
  • The store's added handler counts a landing only in a language the session reads (i18n.languages, e.g. de-CH → de → en). A language fetched before a switch, or read beside the session's language, re-renders no reader.

B. Reading another language once makes later chunks wait for it

Root cause: TopicRegistry.load added its locale to following, and only languageChanged reset it.

Fix: the registry follows the language the session shows (from the start) plus the one switch loadLocale fetches for. The switch ends when the session shows a language, its fetch fails or a later loadLocale replaces it.

  • useLocalesLoaded(locales, namespaces?) now reads instead of loading: it fetches only the namespaces it is given (every registered one when omitted) and follows nothing.
  • isLocaleLoaded takes the same optional namespaces.
  • LocaleSync asks for its locale on every change, also when that locale is already loaded. A switch abandoned for the shown language (fr, then back to de before fr loaded) then stops being followed.
  • The data-notice editor passes ['dataNotice']. Without that, an unfollowed de/fr would refetch every newly registered topic on remount, and the placeholders would be missing meanwhile.

Also changed:

  • packages/ui/README.md describes useLocalesLoaded(locales, namespaces).
  • Manual box PERF-P15 gains the two real-browser checks (Policies & Limits in English; Usage under 5,000 ms latency in German), with a row in pins.md.

Tests

Regression tests, each run first against the unfixed code, where all 7 failed:

  • client.test.tsx:
    • a memoised reader shows the words that land late;
    • the stability test (formerly :58) now also asserts a new shared t when the namespace lands and when the language changes;
    • a landing in an unread language re-renders nothing.
  • topics.test.ts:
    • useLocalesLoaded(['en','de','fr'], ['notice']) fetches only that topic, and a later topic is neither fetched nor waited for in de/fr;
    • LocaleSync fr → de before fr loaded stops following fr;
    • a failed switch stops being followed;
    • the starting language is followed.

Commands run in this worker (Linux, bun 1.4.2, Node 24.21.0) on head e72862664cd489e278426b8b309b3244399c4b05. The full @tale/ui unit run and its tsc ran one edit earlier, and that edit changed only two doc comments. The i18n tests and lint were rerun on this head.

  • bunx vitest --run --project unit src/i18n/client.test.tsx src/i18n/topics.test.ts (packages/ui), against the unfixed code: 7 failed, 18 passed. With the fix: all pass.
  • bunx vitest --run --project unit (packages/ui): 390 files, 4206 tests passed.
  • bunx tsc --noEmit (packages/ui): pass.
  • bunx oxlint --type-aware (packages/ui): 0 diagnostics.
  • bun run lint:manual: ok (4 trees, 1848 boxes).
  • bun services/platform/tests/manual/scripts/check-guide.ts services/platform/tests/manual/suites/performance.md: OK.
  • NODE_OPTIONS=--max-old-space-size=6144 bunx tsc --noEmit (services/platform): pass.
  • bunx oxlint --type-aware on the changed platform file: 0 diagnostics.
  • Single platform test files, each run on its own:
    • data-notice-policy-editor.test.tsx: 10/10, including the German placeholder waiting for its topic.
    • lib/i18n/swiss-loading.test.ts: 1/1.
    • lib/i18n/topic-references.test.ts: 2/2.
    • issue-text.test.ts: 29/29.
    • run-failure.test.ts: 15/15.
    • trigger-issue-text.test.ts: 10/10.
    • project-secrets-tab.test.tsx: 15/15.
    • condition-text.test.ts: 1 failure. condition-values.test.ts: 1 failure. Both fail identically with the base files restored and are unrelated to this change. This worker runs Node 24.21.0 (ICU 78.3, CLDR 48), which formats de-CH 1000 as 1'000; the tests expect 1’000. CI pins Node 22.21.1 from the production image.

Blast radius: a t that changes when its words land also re-runs effects keyed on it. I read the 18 useEffects over t in the platform and packages/ui.

  • 17 are guarded by a ref, nonce or key, or are idempotent.
  • The exception is the disabled-member toast in routes/dashboard/$id.tsx:238 ([isDisabled, t]). It already re-fires on a language change, and can now also re-fire once if accessDenied lands late for a disabled member. It is left as is and noted on the task.

Not done

  • Nothing was run in a browser. A platform stack does not fit this worker, so PERF-P15's new checks have not been executed.
  • Merge-queue-only checks (E2E, Build, Browser, UI shards) run in the queue.

Closes #4433

useT kept one t per language and namespace. When a namespace's messages
landed after its readers rendered (a topic slower than its chunk's 4 s
wait, or fetched again after a failure), the readers re-rendered with the
same t, so a label worked out from it in useMemo(..., [t]) kept the English
fallback until the component remounted or the language changed.

The shared t now belongs to the reader's snapshot: every reader of a
namespace still gets the same t across renders, and a new one when the
language changes or the namespace lands. A landing counts only in a
language the session reads (i18n.languages, e.g. de-CH, de, en), so the
topics fetched before a switch, or read beside the session's language,
re-render no reader.

Refs #4433
TopicRegistry.load added each locale it loaded to the set of followed
locales, and only a language change reset it. A screen that read other
languages through useLocalesLoaded (the data-notice editor reads en, de
and fr) therefore left them followed: every topic registered afterwards was
fetched in them too, every chunk loaded on demand waited up to 4 s for
them, and each read fetched every registered topic. A switch given up for
the language already shown (fr, then de again before fr loaded) left fr
followed the same way.

The registry now follows the language the session shows, from the start,
and the one switch loadLocale fetches for, until the session shows a
language, the fetch fails or a later loadLocale replaces it.
useLocalesLoaded reads instead: it fetches the namespaces it is given, all
registered ones when none are, and follows nothing; isLocaleLoaded takes
the same namespaces. LocaleSync asks for its locale on every change, also
when its messages are in, so a switch still fetching another language is
given up.

Refs #4433
The confidentiality notice editor shows the platform default of each
language as a placeholder, read through getFixedT(locale, 'dataNotice').
It now names that topic to useLocalesLoaded, so opening it fetches the
German and French dataNotice files alone, and the editor mounted again
finds them in at once, whatever topics registered meanwhile.

Refs #4433
PERF-P15 now also opens Policies & Limits in an English session, which
must fetch the German and French dataNotice topic files alone and leave
the next page fetching neither, and opens Usage in a German session
throttled to 5,000 ms latency, whose labels, the granularity and metric
options included, must turn German once its topic lands. The pin says why.

Refs #4433

@tale-review-bot tale-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at e72862664cd489e278426b8b309b3244399c4b05 (task TALE-78, Closes #4433).

  • A: useT (packages/ui/src/i18n/client.tsx). t is now cached per namespace with the useSyncExternalStore snapshot it was bound at (language plus that namespace's landings). Every reader of a namespace shares one t until the language changes or its words land; then it gets a new t, so a useMemo(…, [t]) label is worked out again. The store's added handler counts a landing only in a language the session reads (i18n.languages), so fetching another language re-renders no reader.
  • B: the registry (topics.ts, load-locale.ts, sync.tsx).
    • following is derived on each call from the language the session shows (from attach) and at most one switch in progress (load). A switch ends on languageChanged, on its failed fetch, or when a later load replaces it.
    • useLocalesLoaded reads through read(), which leaves both untouched and fetches only the namespaces it is given (isLocaleLoaded takes the same list).
    • LocaleSync names its locale even when loaded, so a switch to fr given up for de before fr loaded stops being followed. Its show timing is unchanged.
    • The data-notice editor passes ['dataNotice'].
  • Tests. I staged and read red-before-fix.log, which is anchored to main 9be5cadac plus the new tests only. All 7 new or amended tests (client.test.tsx 3, topics.test.ts 4) fail there for the issue's reasons, with 18 passing.
    • The 3 client.test.tsx tests: t does not change when the namespace lands, a memoised label stays in English, and a landing in an unread language re-renders a reader.
    • The 4 topics.test.ts tests: the starting language is not followed, an abandoned switch stays followed, a failed switch stays followed, and a side read is followed.
    • On the head, the @tale/ui unit job ran as real runs (cache misses) in Checks run 40919286398.
  • Contract.
    • Branch fix/i18n-topic-landing-follow, off main 9be5cadac.
    • Four atomic commits, with scopes ui, platform and manual (all in .commitlintrc.json), 56–67 characters. The title is 70.
    • packages/ui/README.md is updated, and manual box PERF-P15 gains the two real-browser checks, with a pins.md row.
    • No strings change.
  • Security: no secret, permission, dependency or workflow change.
  • Required checks at this head: all seven CI ready (...) contexts passed. The runs are Commitlint 40919286459, SAST 40919286422, Security 40919286526, CLI 40919286404, E2E 40919286485, Build 40919286482 and Checks 40919286398.
  • Non-blocking, worth its own issue: t now changing on a landing re-runs effects keyed on t. The Coder's audit found one that shows something: the disabled-member toast at services/platform/app/routes/dashboard/$id.tsx:238 can show a second time if accessDenied lands late. It already re-fires on a language change; a ref guard fixes both.
  • Not run by me: the tests locally, and the new PERF-P15 browser checks (not executed by anyone yet).

@yannickmonney yannickmonney reopened this Oct 29, 2026
@tale-review-bot
tale-review-bot enabled auto-merge (squash) October 29, 2026 20:19
@tale-review-bot

Copy link
Copy Markdown
Collaborator

Reviewer: not landing yet. The approved head e72862664cd489e278426b8b309b3244399c4b05 has no CI round under the current workflows.

  • The newest Checks run on this head, 40947245064 (created 20:14 UTC), checked out Merge e72862664cd489e278426b8b309b3244399c4b05 into 9be5cadacb5f59cd6b2cc67c7840e3c0101bdde2 (merge commit 3ac70d4). That is main from before 0da08205 ("ci: land each pull request on its own, without the merge queue"), so the run uses the old workflows.
  • In that run, UI (both jobs), Browser, Performance and Backend integration were skipped. The current .github/CI.md has a pull request run every suite its paths owe. Its CI ready (Checks) job is still queued.
  • What lands it: a fresh round on the same head under the current workflows. Closing and reopening the pull request rebuilds its test merge on the current main; draft→ready does not. My approval of e72862664cd489e278426b8b309b3244399c4b05 stands while the head is unchanged. Once every CI ready (...) of that round has finished green, it lands with gh pr merge --squash --auto --match-head-commit e72862664cd489e278426b8b309b3244399c4b05 after a hold read.

@yannickmonney

yannickmonney commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Reopened so the checks run again. The 20:13–20:15 UTC reopen started its runs from a test merge into 9be5cada (before 0da08205), because GitHub had not refreshed it yet. This reopen's runs start from the test merge 2f2c6ea108, into 0da08205. The head is unchanged (no new commit).

@yannickmonney

Copy link
Copy Markdown
Contributor

Landed on train as 4d4fa3d: squashed at the approved head after the fast gate (formatting, typecheck, build). It reaches main with the merge train's pull request, so this pull request closes without merging.

yannickmonney pushed a commit that referenced this pull request Oct 30, 2026
Reviewed and approved in pull request #5084 at e728626.

Closes #4433
Task: TALE-78
@yannickmonney
yannickmonney deleted the fix/i18n-topic-landing-follow branch October 30, 2026 10:32
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.

bug(i18n): a topic that lands late misses memoised labels, and reading other languages once makes later chunks wait for them

3 participants