Repository navigation
Conversation
根因(issue Tencent#4732):attached 中 initStyle 同步调用 getMenuRect 后立即读取 this.data._menuRect,而真机上 setData 是异步的,此时仍为 null,initStyle 直接 return,--td-navbar-height/--td-navbar-padding-top 等变量缺失,首屏导航栏与右上角 胶囊错位;切后台回来由胶囊 weight-change 事件触发重排才归位。 修复: 1) initStyle 拆为 getMenuRect(取数)+ applyStyle(纯计算),getMenuRect 的 setData 回调中调用 applyStyle,保证胶囊信息落地后立即补算样式; 2) getLeftRect 增加 _menuRect/_leftRect 空值守卫,消除冷启动窗口期潜在 TypeError; 3) 新增 cold-start 单测:模拟真机胶囊信息,断言首屏渲染即写入对齐变量。 本地验证:navbar 全量套件 12/12 通过(demo 6 + index 5 + cold-start 1),快照不变。
lnuxe
requested review from
anlyyao,
betavs,
jarmywang,
jin0209,
novlan1 and
zydemail
as code owners
November 17, 2026 07:33
Keep a single unit test file per component, as requested in the review of Tencent#4720: only parent, child and utility modules get their own files. Refs Tencent#4732.
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.
🤔 PR 的性质
🔗 关联 issue
fix #4732
💡 根因分析
attached()中initStyle()同步调用getMenuRect()后立即读取this.data._menuRect。真机上setData是异步的,此时_menuRect仍为null,initStyle直接return——--td-navbar-height/--td-navbar-padding-top等胶囊对齐变量缺失,首屏导航栏内容与右上角胶囊错位;直到切后台回来、胶囊weight-change事件触发重排才归位(与 issue 中「切后台后归位」现象一致)。开发者工具/simulate 的
setData近似同步,故模拟器不重现。🔧 修复方案
initStyle拆为getMenuRect(取数)+applyStyle(纯计算)。getMenuRect在setData回调中调用applyStyle—— 胶囊信息落地后立即补算样式,不再依赖同步时序;两者不再互相触发。getLeftRect中_menuRect未落地时直接返回(原先this.data._leftRect.right有冷启动窗口期 TypeError 隐患)。__test__/cold-start.test.js模拟真机胶囊信息(wx.getMenuButtonBoundingClientRect),断言首次渲染周期即写入--td-navbar-padding-top/--td-navbar-height。✅ 自测结果
📝 更新日志