Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tab组件中,对数组为空的判断方法不安全 #663

Closed
1 of 7 tasks
Marla62 opened this issue Jul 12, 2024 · 0 comments
Closed
1 of 7 tasks

tab组件中,对数组为空的判断方法不安全 #663

Marla62 opened this issue Jul 12, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Marla62
Copy link

Marla62 commented Jul 12, 2024

这个 Issue 涉及以下平台:

  • 微信小程序
  • 支付宝小程序
  • 百度小程序
  • 头条小程序
  • 快手小程序
  • QQ 轻应用
  • Web 平台(H5)

BUG 描述
tab组件中,对数组为空的判断方法不安全,当tabRects为空数组,index是undefined时,得到的tabRect是undefined,同时tabRect作为空指针参与了下方的计算
复现步骤

期望结果

实际结果

截图

环境

附加信息
node_modules/@antmjs/vantui/es/tabs/index.js

const scrollIntoView = function(index) {
    if (!scrollable) {
        return;
    }
    index = index !== null && index !== void 0 ? index : currentIndex;
    Promise.all([
        getAllRect(null, `.tabs-com-index${indexRef.current} .van-tab`),
        getRect(null, `.tabs-com-index${indexRef.current} .van-tabs__nav`)
    ]).then(([tabRects, navRect])=>{
        // tabRects是个空数组 同时index是0
        if (tabRects && navRect) {
            console.log('tabRects:', tabRects, index);
            const tabRect = tabRects[index];
            console.log('tabRect:', tabRect);
            const offsetLeft = tabRects.slice(0, index).reduce((prev, curr)=>prev + curr.width, 0);
            setState((pre)=>{
                return _object_spread_props(_object_spread({}, pre), {
                    //  tabRect.width报错:不能从undefined上读取width属性
                    scrollLeft: offsetLeft - (navRect.width - tabRect.width) / 2
                });
            });
            if (!scrollWithAnimation) {
                nextTick(()=>{
                    setState((pre)=>{
                        return _object_spread_props(_object_spread({}, pre), {
                            scrollWithAnimation: true
                        });
                    });
                });
            }
        }
    });
};
@zuolung zuolung added the bug Something isn't working label Jul 18, 2024
@zuolung zuolung closed this as completed Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants