fix(lang): 恢复 common 和 components 节点校验

This commit is contained in:
2026-09-20 16:15:48 +08:00
parent c104f6c443
commit ae5921aa90

View File

@@ -489,27 +489,36 @@ function isBundleComplete(tree) {
return false;
}
// 2) tree 不能是空对象(空对象没有任何可用文案, 显然不可用)
// 2) tree 不能是空对象(空对象没有 common 也没有 components, 显然不可用)
const treeKeys = Object.keys(tree);
if (treeKeys.length === 0) {
return false;
}
// === 粗粒度校验(与上方设计哲学一致) ===
// 不再硬性要求 common / components 节点必须同时存在。
// 远端可能在某些时刻少发某个节点(部署期间、缓存未刷新、租户未配置 common 等),
// 此时仍应让 boot 成功写入 remoteTreeCache, 缺失字段由 $lang() 自然回落为空,
// UI 降级显示(空文案/空按钮文字), 而不是让整个 boot 失败导致整站变英文 / raw key。
// 软校验: components.privacyPopup(节点存在才检查, 避免 tree.components 为 undefined 时报错)
const privacyPopup = tree.components && tree.components.privacyPopup;
if (privacyPopup && typeof privacyPopup === 'object') {
// defaultAppNameMp 存在性仅作诊断, 不阻止 boot
if (typeof privacyPopup.defaultAppNameMp !== 'string' || !privacyPopup.defaultAppNameMp) {
// 软校验不阻止 boot, 仅记录(暂无控制台输出, 避免污染生产)
}
// 3) tree 必须有 common 节点(基础文案, 几乎所有 UI 都依赖)
if (!tree.common || typeof tree.common !== 'object') {
return false;
}
// 4) tree 必须有 components 节点(组件级文案)
if (!tree.components || typeof tree.components !== 'object') {
return false;
}
// === 以下为软校验(只 warn 不 return false) ===
// 设计: 不再因为"缺某个 key"就让整个 boot 失败
// 缺失的字段让 $lang() 自然返回空, UI 降级显示
// 软校验 1: components.privacyPopup
const privacyPopup = tree.components.privacyPopup;
if (!privacyPopup || typeof privacyPopup !== 'object') {
// 软校验不阻止 boot, 仅记录(暂无控制台输出, 避免污染生产)
} else if (typeof privacyPopup.defaultAppNameMp !== 'string' || !privacyPopup.defaultAppNameMp) {
// 软校验不阻止 boot, 仅记录(暂无控制台输出, 避免污染生产)
}
// 软校验 2: 哪些 key 看起来像隐私弹窗,但在错误位置?(诊断)
// 此处仅保留注释说明, 不在生产代码中输出
return true;
}