Repository navigation
Conversation
`typeof '' === 'string'` is true, so an empty string fell into the branch that
renders a button and produced an empty, still clickable one. `wx:if={{_cancel}}`
received an object and stayed true.
Dialog.alert() relies on that empty string to drop the cancel button, so it also
leaked whatever cancelBtn the reused instance declared. Move cancelBtn after the
spread so the intent survives.
Fixes Tencent#4738
lnuxe
requested review from
anlyyao,
betavs,
jarmywang,
jin0209,
novlan1 and
zydemail
as code owners
November 23, 2026 04:46
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
Fixes #4738
💡 需求背景和解决方案
问题:
cancelBtn: ''想表达「不显示取消按钮」,实际会渲染出一个空的、可点击的按钮。dialog.ts的 observer 用typeof btn === 'string'判断「有文案」,而typeof '' === 'string'同样为真,于是空字符串走进了渲染分支:wx:if="{{_cancel}}"拿到对象,恒为真。解决方案:把「为空」的判断提到最前面,空字符串 /
null/undefined一律不渲染。顺带修掉
Dialog.alert()里cancelBtn: ''的展开顺序:它写在...mergedOptions之前,会被实例上的cancelBtn覆盖,导致复用一个写过cancel-btn的实例时,alert 会带出取消按钮。回归测试(
packages/components/dialog/__test__/alert-plugin.test.js)Dialog.alert()+ 实例上有cancelBtn="cancel"→ 取消按钮数量<t-dialog cancelBtn="" />→ 取消按钮数量<t-dialog cancelBtn="cancel" />→ 取消按钮数量 / 文案(守卫)cancelcanceldialog 全量 3 个测试套件通过,无快照变更;
eslint干净。📝 更新日志
fix(Dialog):
cancelBtn为空字符串时不再渲染空按钮,Dialog.alert()不再带出取消按钮本条 PR 不需要纳入 Changelog
☑️ 请求合并前的自查清单