Repository navigation
Commit 2e19f36
fix(console): the language seed's me/localization leaves at parse time, beside discovery (#35618)
Fixes #35534
Refs #35455
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:新设备首次打开控制台时,取界面语言的请求在页面一开始就发出,不再等整包脚本下载完;托管环境下首屏可少等约一次服务器往返,语言判断结果不变。
- 为什么做:属于“控制台首屏请求串行”专题(托管环境打开要 9–10 秒),这是其中语言请求那一段等待。
- 出错会怎样:最坏情况是首次访问多发一次语言请求,或界面先用默认语言;直接撤回本次合并即可恢复原样。
- 要你做什么:无。
## What changes
On a device's true first visit (no stored language choice, no cached
seed), `seedTenantLanguage()` asks `GET /api/v1/auth/me/localization`
before React mounts. Asked from the bundle, that request waited for the
105-file eager module graph to download and evaluate. It needs only
discovery's `locale.supported`, and discovery is already a parse-time
request.
1. **`index.html` gets a parse-time `startEarlyLanguageSeed` script,
after `startEarlyDiscovery`.** It applies the seed's own gates: an
explicit choice (`objectui-locale`) or a cached seed
(`objectui-locale-seed`) sends nothing, and blocked storage reads as
neither, as in the seed. Like the seed, it does not wait for the
session. It hangs off the parse-time discovery answer and sends the
seed's request byte for byte: the same URL through the same
`%VITE_SERVER_URL%` substitution, `credentials: 'include'`, the same
`Accept`, and the same `Accept-Language`. That header is the browser's
language in the app's spelling when `locale.supported` lists it, else
none (ruling 6915665005, #34392). The pending `Response` goes into
`Symbol.for('objectui.earlyLanguageSeed')`. A failed discovery sends
nothing.
2. **`languageSeed.ts` takes it once (`takeEarlySeedRequest`), only when
it is the request the seed would send.** The test is an equal
`inflightGetKey`: URL, credentials and headers, `Accept-Language`
included. The seed hands the parse-time response to the same
`sharedGetJson` call as its transport. Unchanged: the in-flight sharing
with `LocalizationFetchProvider`, the error path, slice 1's
settled-answer hand-off, and the 500 ms race with its fallback. The
first look spends the slot, and the script sends nothing after it. So a
mismatch, or a script that has not sent yet, leaves exactly one request:
the seed's own.
3. **The language ladder is spelled a second time, inside the inline
script.** It is `resolveLocaleAmong` over the platform locale table,
copied because a classic inline script cannot import. That copy can
never change the language: the seed takes only a byte-equal request. A
drift therefore costs one extra request, and a matrix pin catches it
(Tests). `main.tsx` and `LocalizationFetchProvider.tsx` are not edited.
No spec, server, `ui/packages/**`, endpoint or i18n key is touched.
## Tests
New top-level describe in
`ui/apps/console/src/__tests__/sessionCheckBootDedup.test.tsx` (the
parse-time harness: it executes the shipped `index.html` scripts against
the real modules):
- The script is one inline classic script, placed after the discovery
script it reads.
- It leaves once discovery answers, before any bundle code runs, with
the stated language (A3 pin 1).
- One cold load, one `me/localization` (A3 pin 2). End to end with
`VITE_SERVER_URL` set: the parse-time request, then the real
`seedTenantLanguage()` (seed cached before the race resolves, so the
locale is still applied before first paint), then the real
`LocalizationFetchProvider` served from the seed's settled answer. One
request, one discovery.
- Drift pin: the parse-time `Accept-Language` equals the real
`pickPreferredLocale()` for every platform tag and read alias
(enumerated from `@objectstack/spec/system`, upper-cased too, plus
non-table tags) against 34 supported lists.
- CONTROL: a parse-time request the seed would not send is never taken.
The seed sends its own, with the right header.
- CONTROL: a stored explicit language choice still wins, and a cached
seed still applies. Nothing is sent at parse time or by the seed.
- CONTROL: a signed-out first visit sends one request, as the seed did,
and caches nothing.
- CONTROL: the race keeps its bound and its fallback. With the request
still open the boot goes on unseeded, the late answer is cached for the
next boot, and a provider mounted meanwhile joins the same request.
- CONTROL: a failed parse-time discovery sends nothing early. The seed
asks for both itself, once each.
- Blocked storage still sends, as the seed does.
<details><summary>Runs (product code and tests at e422cc7; head
1562fae adds only the changeset)</summary>
- Under the verify lock: `pnpm exec vitest run --maxWorkers=2` on
`sessionCheckBootDedup.test.tsx`, `localizationBootDedup.test.tsx`,
`languageSeed.test.ts`, `LocalizationFetchProvider.test.tsx`: `Test
Files 4 passed (4)`, `Tests 101 passed (101)`, `VERDICT command-exit 0`.
The drift matrix takes 2.7 s.
- `pnpm --filter @object-ui/console run type-check`: `VERDICT
command-exit 0`. `--listFiles` includes the test file.
- eslint over `languageSeed.ts` and the test file: exit 0.
- `pnpm --dir ui exec vitest run --maxWorkers=2 scripts/` (derived):
`Test Files 171 passed | 2 skipped (173)`, `VERDICT command-exit 0`.
`pnpm check:new-line-citations`: 0 new citations.
- Ablation 1, with `scripts/ablation-replace.mjs` (`anchor 1 -> 0`,
restored `blob == HEAD`, `git diff HEAD` empty): the seed no longer
takes the parse-time response. Three pins go red with `expected ... to
have a length of 1 but got 2`: one cold load, signed out, and the race.
`Tests 3 failed | 45 passed (48)`.
- Ablation 2, the same tool: the inline alias `'zh-TW': 'zh-Hant'` is
dropped. The drift pin goes red, e.g. `"zh-HK" among ["zh-CN","zh-TW"]:
sent zh-CN, seed zh-TW`. `Tests 1 failed | 47 passed (48)`.
</details>
<details><summary>Readings: A1-A3, built console, before (e25ca63) and
after (this branch)</summary>
Method: a turbo build of the showcase closure and `@object-ui/console`
in this tree, then `packages/console/build-dist.sh`, served by
`objectstack dev --fresh` from `examples/app-showcase` on a private
port. Headless Chromium 1440x900, a new context per load. Resource
Timing, plus the CDP initiator of every `me/localization`. Layer = chain
depth, as in the #35455 report. cold = cookie only (no Bearer, no stored
language, no seed). warm = cookie + Bearer. signed out = no cookie.
Shared 4-core box, so the times are shared-box ms.
A1 (before, e25ca63): the seed's request is module-issued
(`framework-*.js` frames) on 15/15 loads. It leaves at 466-563 ms cold,
429-519 ms warm and 451-644 ms signed out. Every load fetched 105 JS
files first; the last one ended at 315-514 ms.
A2: the parse-time point with `locale.supported` is the
`startEarlyDiscovery` answer. The new script is chained on it. The seed
takes the pending `Response` through `sharedGetJson`'s transport
argument after an `inflightGetKey` equality check.
| page / posture | me/localization leaves, before | after | initiator
before -> after | me/localization count before -> after | chain depth
before | after |
|:--|:--|:--|:--|:--|:--|:--|
| list cold | 529 / 522 / 466 ms | 149 / 81 / 159 ms | module -> inline
index.html | 1/1/1 -> 1/1/1 | 9 / 10 / 11 | 10 / 11 / 11 |
| record cold | 563 / 561 / 506 | 86 / 83 / 166 | module -> inline |
1/1/1 -> 1/1/1 | 12 / 12 / 11 | 12 / 12 / 12 |
| list warm | 456 / 466 / 519 | 121 / 176 / 187 | module -> inline |
1/1/1 -> 1/1/1 | 10 / 11 / 10 | 9 / 11 / 11 |
| record warm | 474 / 491 / 429 | 133 / 159 / 93 | module -> inline |
1/1/1 -> 1/1/1 | 12 / 11 / 12 | 12 / 11 / 12 |
| signed out (lands on /login) | 451 / 636 / 644 | 116 / 137 / 199 |
module -> inline | 1/1/1 -> 1/1/1 | 4 / 4 / 4 | 4 / 4 / 4 |
The request keeps its layer (L2, after discovery), so chain depth does
not move. The gain is wall time on the path to the mount: locally the
seed's own round trip was 10-17 ms, so the local mount barely moves.
Latency probe (`me/localization` responses held 300 ms, list cold, 3
loads each): the first post-mount request (`me/permissions`) left at 937
/ 993 / 935 ms before and 610 / 551 / 552 ms after. The first data read
left at 1946 / 2211 / 1634 ms before and 1664 / 1601 / 1483 ms after.
Every load stated `Accept-Language: en` in both builds, the same
language.
</details>
## Acceptance notes
- The language ladder now has a third spelling, in `index.html`, beside
`resolveLocaleAmong` and the spec table it reads. The inline script
cannot import, and the alternatives were outside this card's fence: a
build-time HTML transform in `vite.config.ts`, or a server change. A
drift there costs one request and never a language, because the seed
takes only a byte-equal request. The drift pin enumerates the spec's own
table, so a new tag or alias in the spec reds this test until the inline
copy follows.
- The owner count for the slice-1 hand-off is read when the seed takes
the request, as before. The parse-time request carries the cookie
session the page was loaded with, the same session the discovery and
get-session hand-offs already assume.
- A1 also shows the signed-out first visit sends `me/localization`
(answered `authenticated: false`). That is unchanged and kept on
purpose: the seed has never waited on the session, and the dispatch says
to keep what it does today.
## Verification
Read first, by risk: `ui/apps/console/index.html`
`startEarlyLanguageSeed` (the gates and `resolveAmong`);
`ui/apps/console/src/languageSeed.ts` `takeEarlySeedRequest` and the
`sharedGetJson` transport argument; the new describe's drift-matrix
test.
Two minutes: `cd ui && pnpm exec vitest run
apps/console/src/__tests__/sessionCheckBootDedup.test.tsx`. Expect 48
tests green, 11 of them in the describe named for this card.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CZrgaiMgTJCnswR6jQ)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent b38e133 commit 2e19f36
4 files changed
Lines changed: 374 additions & 1 deletion
File tree
- .changeset
- ui/apps/console
- src
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
261 | 363 | | |
262 | 364 | | |
263 | 365 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
30 | 35 | | |
31 | 36 | | |
32 | 37 | | |
| |||
82 | 87 | | |
83 | 88 | | |
84 | 89 | | |
| 90 | + | |
| 91 | + | |
85 | 92 | | |
86 | 93 | | |
87 | 94 | | |
| 95 | + | |
| 96 | + | |
88 | 97 | | |
89 | 98 | | |
90 | 99 | | |
| |||
108 | 117 | | |
109 | 118 | | |
110 | 119 | | |
| 120 | + | |
| 121 | + | |
111 | 122 | | |
112 | 123 | | |
113 | 124 | | |
| |||
685 | 696 | | |
686 | 697 | | |
687 | 698 | | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
0 commit comments