Skip to content

fix(components): 修复@trao/components swiper组件销毁时的报错#19353

Open
niljie wants to merge 1 commit into
NervJS:mainfrom
niljie:fix/swiper-loop-destroy-wrapper
Open

fix(components): 修复@trao/components swiper组件销毁时的报错#19353
niljie wants to merge 1 commit into
NervJS:mainfrom
niljie:fix/swiper-loop-destroy-wrapper

Conversation

@niljie

@niljie niljie commented Jun 17, 2026

Copy link
Copy Markdown

这个 PR 做了什么? (简要描述所做更改)

TypeError. Cannot read properties of undefined (reading 'children'). in e.loopDestroy at line 2:60102

Swiper 在 circular 模式下,外部子节点变化时会先调用 loopDestroy() 恢复 DOM 顺序,再重新初
始化。
但在某些场景下,Swiper 内部的 wrapper 节点可能已经被移除或重置,此时继续调用 loopDestroy()
会导致 Swiper 内部访问 wrapper children 时抛错。

这个 PR 是什么类型? (至少选择一个)

  • 错误修复 (Bugfix) issue: fix #
  • 新功能 (Feature)
  • 代码重构 (Refactor)
  • TypeScript 类型定义修改 (Types)
  • 文档修改 (Docs)
  • 代码风格更新 (Code style update)
  • 构建优化 (Chore)
  • 其他,请描述 (Other, please describe):

这个 PR 涉及以下平台:

  • 所有平台
  • Web 端(H5)
  • 移动端(React-Native)
  • 鸿蒙(Harmony)
  • 鸿蒙容器(Harmony Hybrid)
  • ASCF 元服务
  • 快应用(QuickApp)
  • 所有小程序
  • 微信小程序
  • 企业微信小程序
  • 京东小程序
  • 百度小程序
  • 支付宝小程序
  • 支付宝 IOT 小程序
  • 钉钉小程序
  • QQ 小程序
  • 飞书小程序
  • 快手小程序
  • 头条小程序

Summary by CodeRabbit

发布说明

  • Bug 修复
    • 改进了轮播组件的稳定性,添加了初始化检查机制,防止在组件尚未完成初始化时出现异常。

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a25745da-74c3-4573-9a35-e76a2c700ce6

📥 Commits

Reviewing files that changed from the base of the PR and between 0db37ec and 775d211.

📒 Files selected for processing (2)
  • packages/taro-components/__tests__/swiper.spec.tsx
  • packages/taro-components/src/components/swiper/swiper.tsx

Walkthrough

watchSwiperWrapper 方法中新增一行对 this.swiper.wrapperEl 的空值判断,当其不存在时直接返回。同时在测试文件中新增一个测试用例,验证该场景下 loopDestroy 不会被调用。

Changes

wrapperEl 空值保护及测试

Layer / File(s) Summary
wrapperEl 空值保护实现与测试
packages/taro-components/src/components/swiper/swiper.tsx, packages/taro-components/__tests__/swiper.spec.tsx
watchSwiperWrapper 在执行后续逻辑前新增 wrapperEl 存在性检查,不存在时提前返回;测试用例模拟 circular: trueparams.loop: truewrapperEl 为空的场景,断言 loopDestroy 未被调用、appendChild 正常插入子元素。

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 小兔蹦蹦跳,循环滑块要检查,
wrapperEl 若为空,直接把路堵啦~
loopDestroy 不乱跑,测试验证无差,
一行守护代码,平安迎春花!✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题准确总结了主要变更:修复swiper组件销毁时的报错问题,与代码变更内容(在watchSwiperWrapper中添加wrapper判定以避免错误)完全对应。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

This was referenced Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant