refactor(app-shell): 删除 RecordFormPage 中不可达的 i18n defaultValue 兜底 - #3516
Merged
Conversation
…ordFormPage
The page handed i18next an inline `defaultValue` on eight `t()` calls. Seven of
those branches were unreachable: their keys are defined in all ten locale packs
and `all-locales-key-parity.test.ts` pins that permanently, so i18next always
resolved the pack value and the fallback could never render.
What the dead fallbacks did do is carry a second, unwatched English spelling of
the same string. `form.createTitle`'s default read `New {label}` while the pack
says `Create {{object}}` — a different verb for one title at one call site. Had
the key ever been renamed or dropped, the title would have silently changed
from "Create Contacts" to "New Contacts" with every test still green. Deleting
them makes "this title has exactly one English spelling" a structural fact
rather than a coincidence, consistent with the declared=enforced precedent in
objectui#3470/#3483.
`form.createTargetOrg` is KEPT and documented: it is defined in no pack, not
even `en`, so its `defaultValue` is genuinely what renders.
Rendered copy is unchanged in every locale — verified by restoring the deleted
limbs on top of the new test file, which stays green (a dead branch cannot move
an assertion), and by a counterfactual: with `form.createTitle` removed from
`en`, the old code silently rendered "New Contacts" while the new code renders
the raw key and the new pack-coverage test fails loudly.
Fixes #3469
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GTRjn8xBqp75dk7kFupVRt
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
yinlianghui
marked this pull request as ready for review
August 7, 2026 02:13
This was referenced Aug 7, 2026
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.
Fixes #3469
采用 issue 分诊结论的 B 向:删掉死的
defaultValue分支,而不是把它改成和语言包一致的拼法。与 #3470/#3483 的「declared = enforced、消费端不留容忍」先例一致。改了什么
packages/app-shell/src/views/RecordFormPage.tsx原本在 8 处t()调用上挂了内联defaultValue。逐一评估后:form.createTitleNew ${label},包里是Create {{object}})form.editTitleform.createSuccessform.updateSuccessform.saveRecordcommon.backcommon.cancelform.createTargetOrgen都没有删掉的七条,key 由
all-locales-key-parity.test.ts永久钉住必然存在,i18next 永远解析得到包里的值,兜底分支不可能被渲染。它们真正的作用是给同一条文案带了第二处没人看管的英文拼法:form.createTitle的默认值写的是New ${label},包里却是Create {{object}},同一个标题、同一个调用点、两个动词。哪天这个 key 被改名或删掉,页面标题就会从Create Contacts悄悄变成New Contacts,而且没有任何测试会红。保留的那一条已在代码里写清原委:
form.createTargetOrg在十个包里都没有定义,i18next 是真的 miss,兜底就是实际渲染出来的东西 —— 删了会把裸 key 摆到页面上。这也是该徽标在十种语言下都是英文的原因。把 key 回填进en(parity 测试会带着其余九个包跟上)才是正解,届时在同一个改动里删掉这条兜底,新测试里有一条断言就是提醒这件事的。行为不变的证据(以及反向验证的真实方向)
「把删掉的分支放回去看测试变红」在这个改动上从构造上就不可能成立,预测在跑之前就已写进测试文件头:key 在包里,i18next 根本不会去看
defaultValue,所以把defaultValue加回来,断言一条都不会动。这正是 issue 报告的那个缺陷本身 —— 一段没有任何测试能看见的死分支。所以这里如实记录三个方向的实测:git checkout origin/main -- RecordFormPage.tsx把八处defaultValue全部放回,新测试文件 16/16 依旧全绿。form.createTitle从en包里删掉,旧代码渲染出PROBE_TITLE=[New Contacts]—— 动词静默改变,没有任何测试信号。PROBE_TITLE=[form.createTitle](裸 key + dev missing-key 告警),且新增的覆盖率断言直接变红:form.createTitle missing from: en。反事实用的语言包临时改动是一次性探针,已还原,未进入本 PR(
git status已核验)。新增测试
packages/app-shell/src/views/RecordFormPage.i18n.test.tsx(16 个用例),钉住删除之后真正成立的不变式:en和zh两种语言下各断言一次 —— 任何硬编码的英文默认值都无法同时满足这两条(zh下标题是新建Contacts)。New Contacts不在页面上。form.createTargetOrg的两条:一条钉住它当前在十个包里都不存在(所以兜底必须留),一条钉住徽标确实渲染出Creates in Acme Inc而不是裸 key。验证
pnpm exec vitest run packages/app-shell/src/views/RecordFormPage.i18n.test.tsx packages/i18n/src/__tests__/all-locales-key-parity.test.ts→ 36 passedpnpm exec vitest run packages/app-shell/src/views(消费半径清扫)→ 180 files / 1585 passedpnpm exec turbo run type-check --filter=@object-ui/app-shell→ 通过pnpm exec eslint两个改动文件 → 0 errornode scripts/check-control-bytes.mjs/check-changeset-no-major.mjs→ 通过顺带发现(未在本 PR 修改)
form.createTargetOrg被组织租户徽标消费,却在十个语言包里全部缺失 —— 属于「组件引用了不存在的 key」这一类漂移,与本 issue 是两件事,已另行记录待 PM 分诊。🤖 Generated with Claude Code
https://claude.ai/code/session_01GTRjn8xBqp75dk7kFupVRt
Generated by Claude Code