Backport #30227 by wxiaoguang The old code is inconsistent and fragile, and the UI isn't right. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>