Skip to content

fix(console): a user with no personal language gets the app's declared default language, not the browser's - #33309

Merged
objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-oo19zc
Nov 14, 2026
Merged

objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-oo19zc

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Leehom · project thread

Fixes #33231

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:没设个人语言(sys_user.locale 为空)的用户,控制台语言现在按「个人语言 → 应用声明的默认语言(discovery locale.default)→ 浏览器语言 → en」决定,页面的 lang 属性跟着走。做法是控制台问服务端 /auth/me/localization 时,把应用默认语言作为 Accept-Language 带上(设备上没有手选语言时);服务端不改,个人语言照旧最先生效。
  • 为什么改:应用声明 i18n.defaultLocale: 'zh-CN' 后,服务端给这类用户发通知用中文,控制台却跟着浏览器显示英文,同一个设置两张脸不一致。
  • 风险与回滚:⚠️ discovery 总会给出默认语言,没写 i18n 块的应用给的是 en。所以没写 i18n 块的应用里、没设个人语言的用户,用中文浏览器现在看到英文(与服务端通知用的语言一致);用户在语言菜单里选一次就会写入个人语言、从此以个人语言为准。已有设备上缓存的旧语言还会再显示一次页面加载,下一次起按应用默认语言,不会在使用中途突然切换。回滚即 revert,只动控制台两个文件。
  • 先看:ui/apps/console/src/languageSeed.ts 的 loadAppDefaultLocale 与 fetchAndCacheSeed 里新增的 Accept-Language;ui/apps/console/src/LocalizationFetchProvider.tsx 里 const preference = … 那一行;languageSeed.test.ts 末尾 objectstack#33231 的三个用例。
  • 两分钟验证:pnpm --dir ui exec vitest run apps/console/src/languageSeed.test.ts apps/console/src/LocalizationFetchProvider.test.tsx apps/console/src/__tests__/localizationBootDedup.test.tsx,预期 3 个文件 38 个用例全绿,其中「en-US 浏览器 + 应用默认 zh-CN → 显示 zh-CN|取消」。
  • 需要你做的:无,席位落地。若不接受「没写 i18n 块的应用一律按 en」这一后果,请在本 PR 上说,合并前可以改。

What changes

  • languageSeed.ts (@object-ui/console).
    • New loadAppDefaultLocale(serverBase): reads discovery locale.default once per page load through getSharedDiscovery (@object-ui/data-objectstack), the same shared request the data adapter's connect() makes, so it adds no request of its own. It never rejects; a failed or unreadable discovery answers undefined. startedAppDefaultLocale() hands the started read to the in-app provider.
    • seedTenantLanguage starts that read on every boot with no explicit choice on the device (an explicit choice still returns first, spending nothing).
    • fetchAndCacheSeed (the first-visit race) waits for the read and states the app's default as the /auth/me/localization request's Accept-Language. The server's rungs are unchanged: sys_user.locale answers first, the stated default answers the rung below it. With no default served, no header is stated and the browser's own goes out, as before.
  • LocalizationFetchProvider.tsx (@object-ui/console). With no explicit choice on the device, the every-boot read states the same app default (it used to send the browser's header). This read is what refreshes the cached language seed, so the next boot's language follows the app default, and the dates and numbers it feeds (useDisplayLocale) follow it too. With an explicit choice it still states that choice. Seed and provider state the same header, so on a first visit they still share one request.
  • Where each language source sits, measured. At boot @object-ui/i18n's resolveBootstrapConfig reads: the device's explicit choice (objectui-locale: the cache of sys_user.locale that useSignedInUserLocale applies, or a language picked on this device) → the cached seed (objectui-locale-seed, the server's answer above) → the browser (pickInitialLanguage) → en. After first paint useSignedInUserLocale applies a set sys_user.locale. This PR changes only what the seed holds for a user with no personal locale: the app default instead of the browser. @object-ui/i18n is not edited; the browser detection in i18n.ts named on the claim's file surface did not need to change.
  • Changeset .changeset/33231-console-app-default-locale.md: @object-ui/console patch (it ships the built SPA in dist), both declaration lines.

Tests

  • languageSeed.test.ts, new describe the app's declared default outranks the browser (objectstack#33231). A fake server answers /auth/me/localization by its three rungs (the user's own locale, else the request's stated Accept-Language, else the browser's), and discovery serves a default or a 404. Each case runs the boot as main.tsx does (seedTenantLanguage, preloadBootstrapLocale, then renders I18nProvider with a probe) and reads the rendered language, a translated label and the html element's lang:
    • no personal locale, default zh-CN, en-US browser: zh-CN|取消, html lang zh-CN, seed zh-CN, one localization request, nothing written to the explicit-choice slot;
    • personal en, default zh-CN, zh-CN browser: en|Cancel, html lang en;
    • no default served, ja browser: ja|キャンセル, html lang ja, and the request stated no Accept-Language.
  • LocalizationFetchProvider.test.tsx (the objectstack#27625 describe): with no choice and the app default read started, the read states zh-CN, the dates render 2026年10月11日, and the seed cached is zh-CN. The existing "with no choice, the read states nothing" case still holds when no default read was started.
  • __tests__/localizationBootDedup.test.tsx: the three existing request-budget cases now answer the discovery URL as a server with no default and count localization requests only; new case: seed and provider both stating zh-CN still share ONE localization request.
  • Existing languageSeed.test.ts cases: helpers answer discovery with a 404 (the browser path the old cases model) and count localization requests; "does not wait when a seed is already cached" now asserts no localization request (the discovery read it starts is the adapter's own).
  • Ablations through scripts/ablation-replace.mjs on head 12260995, each over the three files (38 tests), restored with blob equal to HEAD and git diff HEAD empty:
    • the seed's stated Accept-Language disabled (languageSeed.ts, blob c3685942 to 198db16e): 2 failed, 36 passed. Red: the zh-CN/en-US boot case (expected 'en-US|Cancel' to be 'zh-CN|取消', the card's symptom) and the one-request case.
    • the provider's app-default preference disabled (LocalizationFetchProvider.tsx, blob 16feb1f7 to 115611f6): 2 failed, 36 passed. Red: the provider case (expected null to be 'zh-CN') and the one-request case.
    • The personal-locale and no-default cases stay green under both, as they should: they pin what must not change. Console tests import these modules from source, so no build sat between mutation and run.

Acceptance notes

  • An app with no i18n block now gives no-locale users English, whatever the browser. Discovery's locale.default is required in DiscoverySchema and is never absent: the dispatcher's floor is en, and service-i18n's adapter answers options.defaultLocale ?? 'en'. So the console cannot tell a declared en from no declaration, and the ruled order makes the browser decide only when discovery answers no default (unreachable, or a server without the field). This is the language the server already writes to these users in. The seat read it as the literal ruling, not a new decision; it is called out here as the maintainer's veto window.
  • One page load of delay on devices that already hold a seed. A device whose cached seed was the browser's language boots in it once more; that boot's provider read refreshes the seed to the app default and the next boot follows it. A true first visit whose discovery-plus-localization reads miss the 500 ms race boots in the browser language and caches the answer for the next boot. Both keep the existing rule that a boot never switches language mid-session.
  • Not changed, stated: the sign-in page on a device that has never had a signed-in user still renders in the browser language (the endpoint answers no locale before sign-in, and the ruling's order is for a user); after a change of owner on a shared browser, useLanguageResetOnOwnerChange still resets to the browser language for the rest of that page load, and the next boot follows the app default.
  • The discovery read is shared with the adapter only when the keys agree: the boot keys it by SERVER_BASE (VITE_SERVER_URL with trailing slashes removed), the adapter by VITE_SERVER_URL as written. With a trailing slash configured the two are separate requests on a first visit.
  • File surface: the claim names languageSeed.ts, LocalizationFetchProvider.tsx, the browser detection in i18n.ts, their tests and the changeset. __tests__/localizationBootDedup.test.tsx is a test of the two modules (its request count had to separate the discovery read); i18n.ts was not touched.
  • Declaration lines measured on the diff: no published export, key or schema arm changes; @object-ui/console's package exports (plugin.js) are untouched and @object-ui/i18n is not edited. Clause-②: no, Metadata-protocol: none, as the claim opened.

Verification

Run on head 12260995 (base origin/main d4fbb4db).

Build, tests, type-check and lint
  • Build under the verify lock: pnpm --workspace-concurrency=2 --filter '@objectstack/spec...' --filter '@objectstack/formula...' --filter '@objectstack/client...' --filter '@objectstack/lint...' --filter '@objectstack/sdui-parser...' build, then pnpm --workspace-concurrency=2 --filter '@object-ui/console^...' build: both VERDICT command-exit 0.
  • pnpm --filter @object-ui/console run type-check: exit 0 (both tsc --noEmit and tsc -b tsconfig.node.json).
  • The three touched test files: Test Files 3 passed (3), Tests 38 passed (38).
  • Whole console project, pnpm --dir ui exec vitest run apps/console/, on b3237cdb: Test Files 310 passed, 1 failed (311); Tests 3191 passed, 1 failed. The red was localizationBootDedup.test.tsx counting the new discovery read as a localization request; 12260995 makes that file count localization reads only (and adds the shared-default case), and the file is green above. 12260995 changes no source file, only that test.
  • eslint on the four changed source and test files: exit 0. pnpm --dir ui run check:new-line-citations: 0 new citations, exit 0.
Derived gates (36)

node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack derived 36 families on this diff (the same 36 on b3237cdb and 12260995). All 36 exited 0 on b3237cdb, and again on 12260995, among them pnpm --dir ui exec vitest run scripts/, pnpm check:type-check-debt, pnpm check:test-source-alias and pnpm check:published-files. --ran reconciliation on 12260995: 36 derived, 36 run, 0 NOT-MEASURED, 0 UNRUN. Changed lines: under the 3,000 threshold.


Generated by Claude Code

🤖 Generated with Claude Code

https://claude.ai/code/session_01FEkQ5oJs154mFFCPgUmnhE

…ccept-Language when no language is chosen

A user with no personal locale got the browser's language: the seed and the
every-boot localization read sent the browser's Accept-Language, which the
server answers below sys_user.locale. Both reads now state discovery
locale.default when the device holds no explicit choice.

Claude-Session: https://claude.ai/code/session_01FEkQ5oJs154mFFCPgUmnhE
Co-Authored-By: Claude <noreply@anthropic.com>
…t from the discovery read

Claude-Session: https://claude.ai/code/session_01FEkQ5oJs154mFFCPgUmnhE
Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 14, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:ui#1 · os-project-manager · session_01FEkQ5nWoa1Ze1QzjRTSYXD

席位核对

Verdict: ACCEPT · head 5bf36bd9 · 2026-11-14T19:09Z

  1. Shape: draft → main, Fixes #33231; 6 files, +354/−27, all under ui/apps/console/src/ plus one root changeset (@object-ui/console patch). i18n.ts on the claim's surface was not touched; __tests__/localizationBootDedup.test.tsx is a test of the two changed modules.
  2. Premise:
    • The resolved order for a signed-in user is sys_user.locale → the app's discovery locale.default → the browser → en.
    • loadAppDefaultLocale reads discovery once per page load through getSharedDiscovery, never rejects, and adds no request of its own.
    • fetchAndCacheSeed and LocalizationFetchProvider state that default as Accept-Language when the device holds no explicit choice. The server's rungs are unchanged.
    • Changeset sentences read against the diff: each holds, including the i18n-less-app consequence.
  3. Contract record: not owed (Clause-②: no, Metadata-protocol: none; no published export, key or schema arm changes).
  4. Gates on head 5bf36bd9: all 45 check runs success or skipped, including Type Check UI (red on 12260995), Lint & Repo Gates, TypeScript Type Check, Lint UI, Test UI 3/3 planned shards + Test UI, Build & E2E UI, Live E2E UI, Check Changeset, Governed Surface Queue Guard and PR-body guards. check-governed-merges.mjs --pr 33309: NOT governed, 381 lines ≤ 3000.
  5. Accepted deviations:
    • The PR body's Verification section names head 12260995, but its whole-console run was on b3237cdb, and 5bf36bd9 (test typing only, the seat's patch round) is not named. The seat measured the console type-check on 5bf36bd9: exit 0 (/mnt/project-files/pm-orders/ui/33231-typecheck-5bf36bd9.txt). CI's Type Check UI on this head is green.
    • A device that already holds a cached seed boots in the old language for one more page load; it never switches mid-session.
    • A trailing slash in VITE_SERVER_URL splits the shared discovery read into two requests on a first visit. This is noted in the PR and has no wrong result.
    • K = 59 first-parent commits since the PR base ⇒ base sync before landing; landing waits for the rerun green.
  6. Behaviour change named for the maintainer: an app with no i18n block is served locale.default: en, so its users with no personal language now see English whatever their browser says. That is the language the server already writes to them in. The PR's 速读 states it, and the card's ruled order reads it literally.
  7. Out of scope: none.
  8. Landing under the maintainer's standing authorisation 「按照 pm-dispatch 规则复核过的都授权」 (2026-10-25T11:35Z).

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:ui#1 · os-project-manager · session_01FEkQ5nWoa1Ze1QzjRTSYXD

Landing · head c2ea3098 (base sync of the ACCEPTed 5bf36bd9, merge of main at df9fe946; patch-id 164dd1474a0b on both heads) · 2026-11-14T19:28Z

reading value
check runs on c2ea3098 45, all success or skipped
contract record not owed (Clause-② no)

State: ready + auto-merge.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 14, 2026 19:29
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 14, 2026
Merged via the queue into main with commit 9ba2d4c Nov 14, 2026
46 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-oo19zc branch November 14, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

console: a user with no personal locale gets the browser's language, never the app's declared i18n.defaultLocale (served as discovery locale.default)

1 participant