Repository navigation
fix(console): a user with no personal language gets the app's declared default language, not the browser's - #33309
Merged
Conversation
…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>
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>
Claude-Session: https://claude.ai/code/session_01FEkQ5oJs154mFFCPgUmnhE Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Author
|
domain:ui#1 · os-project-manager · session_01FEkQ5nWoa1Ze1QzjRTSYXD 席位核对Verdict: ACCEPT · head
|
Contributor
Author
|
domain:ui#1 · os-project-manager · session_01FEkQ5nWoa1Ze1QzjRTSYXD Landing · head
State: ready + auto-merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Leehom · project thread
Fixes #33231
Clause-②: no
Metadata-protocol: none
维护者速读
sys_user.locale为空)的用户,控制台语言现在按「个人语言 → 应用声明的默认语言(discoverylocale.default)→ 浏览器语言 →en」决定,页面的lang属性跟着走。做法是控制台问服务端/auth/me/localization时,把应用默认语言作为Accept-Language带上(设备上没有手选语言时);服务端不改,个人语言照旧最先生效。i18n.defaultLocale: 'zh-CN'后,服务端给这类用户发通知用中文,控制台却跟着浏览器显示英文,同一个设置两张脸不一致。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).loadAppDefaultLocale(serverBase): reads discoverylocale.defaultonce per page load throughgetSharedDiscovery(@object-ui/data-objectstack), the same shared request the data adapter'sconnect()makes, so it adds no request of its own. It never rejects; a failed or unreadable discovery answersundefined.startedAppDefaultLocale()hands the started read to the in-app provider.seedTenantLanguagestarts 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/localizationrequest'sAccept-Language. The server's rungs are unchanged:sys_user.localeanswers 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.@object-ui/i18n'sresolveBootstrapConfigreads: the device's explicit choice (objectui-locale: the cache ofsys_user.localethatuseSignedInUserLocaleapplies, or a language picked on this device) → the cached seed (objectui-locale-seed, the server's answer above) → the browser (pickInitialLanguage) →en. After first paintuseSignedInUserLocaleapplies a setsys_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/i18nis not edited; the browser detection ini18n.tsnamed on the claim's file surface did not need to change..changeset/33231-console-app-default-locale.md:@object-ui/consolepatch (it ships the built SPA indist), both declaration lines.Tests
languageSeed.test.ts, new describethe app's declared default outranks the browser (objectstack#33231). A fake server answers/auth/me/localizationby its three rungs (the user's own locale, else the request's statedAccept-Language, else the browser's), and discovery serves a default or a 404. Each case runs the boot asmain.tsxdoes (seedTenantLanguage,preloadBootstrapLocale, then rendersI18nProviderwith a probe) and reads the rendered language, a translated label and the html element'slang:zh-CN,en-USbrowser:zh-CN|取消, htmllangzh-CN, seedzh-CN, one localization request, nothing written to the explicit-choice slot;en, defaultzh-CN,zh-CNbrowser:en|Cancel, htmllangen;jabrowser:ja|キャンセル, htmllangja, and the request stated noAccept-Language.LocalizationFetchProvider.test.tsx(theobjectstack#27625describe): with no choice and the app default read started, the read stateszh-CN, the dates render2026年10月11日, and the seed cached iszh-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 statingzh-CNstill share ONE localization request.languageSeed.test.tscases: 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).scripts/ablation-replace.mjson head12260995, each over the three files (38 tests), restored with blob equal to HEAD andgit diff HEADempty:Accept-Languagedisabled (languageSeed.ts, blobc3685942to198db16e): 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.LocalizationFetchProvider.tsx, blob16feb1f7to115611f6): 2 failed, 36 passed. Red: the provider case (expected null to be 'zh-CN') and the one-request case.Acceptance notes
i18nblock now gives no-locale users English, whatever the browser. Discovery'slocale.defaultis required inDiscoverySchemaand is never absent: the dispatcher's floor isen, and service-i18n's adapter answersoptions.defaultLocale ?? 'en'. So the console cannot tell a declaredenfrom 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.useLanguageResetOnOwnerChangestill resets to the browser language for the rest of that page load, and the next boot follows the app default.SERVER_BASE(VITE_SERVER_URLwith trailing slashes removed), the adapter byVITE_SERVER_URLas written. With a trailing slash configured the two are separate requests on a first visit.languageSeed.ts,LocalizationFetchProvider.tsx, the browser detection ini18n.ts, their tests and the changeset.__tests__/localizationBootDedup.test.tsxis a test of the two modules (its request count had to separate the discovery read);i18n.tswas not touched.@object-ui/console's package exports (plugin.js) are untouched and@object-ui/i18nis not edited.Clause-②: no,Metadata-protocol: none, as the claim opened.Verification
Run on head
12260995(baseorigin/maind4fbb4db).Build, tests, type-check and lint
pnpm --workspace-concurrency=2 --filter '@objectstack/spec...' --filter '@objectstack/formula...' --filter '@objectstack/client...' --filter '@objectstack/lint...' --filter '@objectstack/sdui-parser...' build, thenpnpm --workspace-concurrency=2 --filter '@object-ui/console^...' build: both VERDICT command-exit 0.pnpm --filter @object-ui/console run type-check: exit 0 (bothtsc --noEmitandtsc -b tsconfig.node.json).pnpm --dir ui exec vitest run apps/console/, onb3237cdb: Test Files 310 passed, 1 failed (311); Tests 3191 passed, 1 failed. The red waslocalizationBootDedup.test.tsxcounting the new discovery read as a localization request;12260995makes that file count localization reads only (and adds the shared-default case), and the file is green above.12260995changes no source file, only that test.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/objectstackderived 36 families on this diff (the same 36 onb3237cdband12260995). All 36 exited 0 onb3237cdb, and again on12260995, among thempnpm --dir ui exec vitest run scripts/,pnpm check:type-check-debt,pnpm check:test-source-aliasandpnpm check:published-files.--ranreconciliation on12260995: 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