Skip to content

fix: 🐛 修复 wd-img-cropper 组件在微信小程序中旋转图片后操作卡顿的问题 - #1112

Merged
Moonofweisheng merged 1 commit into
Moonofweisheng:masterfrom
quantum-rose:fix/wd-img-cropper/revert-is-animation
Jun 22, 2025
Merged

fix: 🐛 修复 wd-img-cropper 组件在微信小程序中旋转图片后操作卡顿的问题#1112
Moonofweisheng merged 1 commit into
Moonofweisheng:masterfrom
quantum-rose:fix/wd-img-cropper/revert-is-animation

Conversation

@quantum-rose

@quantum-rose quantum-rose commented Jun 13, 2025

Copy link
Copy Markdown
Contributor

🤔 这个 PR 的性质是?(至少选择一个)

  • 日常 bug 修复
  • 新特性提交
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • CI/CD 改进
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 代码重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

在微信小程序环境下使用 wd-img-cropper 组件,将图片旋转90度或270度后,可复现此 bug,手势操作会变得卡顿。
检查 dom 发现,image 元素的 transition-duration 属性在不断发生变化,造成的实际体验效果就是手势操作卡顿:

bug-img-cropper

断点发现 revertIsAnimation 不断被调用,且其中一次接收到的值为空对象 {}:

Snipaste_2025-06-13_14-41-21

排查发现接收空对象的那次调用来自 wxs 中的 ownerInstance.callMethod('revertIsAnimation',false),查看微信官方文档
https://developers.weixin.qq.com/miniprogram/dev/framework/view/interactive-animation.html,可以看到 callMethod 的第二个参数只能为 object 类型

image

解决方案是扩大 revertIsAnimation 可接收参数的类型,兼容对象类型参数,对 wxs 中的调用进行特殊处理。

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充

Summary by CodeRabbit

  • Bug Fixes
    • 修复了图片裁剪组件在动画处理时的兼容性问题,提升了动画表现的稳定性。

@netlify

netlify Bot commented Jun 13, 2025

Copy link
Copy Markdown

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit e9488fa
🔍 Latest deploy log https://app.netlify.com/projects/wot-design-uni/deploys/684bd6bd6f8c2a000848c58d
😎 Deploy Preview https://deploy-preview-1112--wot-design-uni.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@vercel

vercel Bot commented Jun 13, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
wot-design-uni ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 13, 2025 7:45am

@coderabbitai

coderabbitai Bot commented Jun 13, 2025

Copy link
Copy Markdown

Walkthrough

本次更改调整了 revertIsAnimation 函数的参数类型,使其可以接受布尔值或包含布尔 value 属性的对象,并相应修改了 setAnimation 函数中对该函数的调用方式。

Changes

文件路径 变更摘要
src/uni_modules/wot-design-uni/components/wd-img-cropper/wd-img-cropper.vue revertIsAnimation 函数参数类型由布尔值扩展为布尔值或带 value 属性的对象,并修改了 setAnimation 中的调用方式。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant wd-img-cropper.vue

    User->>wd-img-cropper.vue: 调用 setAnimation()
    wd-img-cropper.vue->>wd-img-cropper.vue: 调用 revertIsAnimation({value: false})
    wd-img-cropper.vue->>wd-img-cropper.vue: 判断参数类型并设置 isAnimation.value
Loading

Suggested reviewers

  • Moonofweisheng

Poem

小兔挥笔写新篇,
动画参数变灵便。
或真或假皆可传,
代码世界更自然。
轻松切换无烦恼,
跳跃前行乐淘淘! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6026137 and e9488fa.

📒 Files selected for processing (1)
  • src/uni_modules/wot-design-uni/components/wd-img-cropper/wd-img-cropper.vue (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Test Components (wd-img-cropper)
  • GitHub Check: Redirect rules - wot-design-uni
  • GitHub Check: Header rules - wot-design-uni
  • GitHub Check: Pages changed - wot-design-uni
🔇 Additional comments (2)
src/uni_modules/wot-design-uni/components/wd-img-cropper/wd-img-cropper.vue (2)

268-274: 参数校验仍显薄弱,建议兜底处理未知入参

目前仅分 boolean{ value: boolean } 两种情况直接赋值,若传入 {}{ value: 'false' } 等非法对象时,会导致 isAnimation.value 变成 undefined,进而触发类型异常或逻辑错误。可以增加更严格的类型判断并提供默认值。

 function revertIsAnimation(animation: boolean | { value: boolean }) {
-  if (typeof animation === 'boolean') {
-    isAnimation.value = animation
-  } else {
-    isAnimation.value = animation.value
-  }
+  if (typeof animation === 'boolean') {
+    isAnimation.value = animation
+  } else if (animation && typeof animation.value === 'boolean') {
+    isAnimation.value = animation.value
+  } else {
+    // 非法入参时安全降级,避免写入 undefined
+    isAnimation.value = false
+  }
 }

[ suggest_optional_refactor ]


646-651: WXS 调用方式已符合平台规范,👍

将第二个参数替换成对象 {value:false} 有效规避了微信小程序 callMethod 只能传对象的限制,能够阻止无效调用导致的持续卡顿问题,改动正确。


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 85.27%. Comparing base (6026137) to head (e9488fa).

Files with missing lines Patch % Lines
...n-uni/components/wd-img-cropper/wd-img-cropper.vue 60.00% 2 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #1112       +/-   ##
===========================================
+ Coverage   52.18%   85.27%   +33.09%     
===========================================
  Files          11        7        -4     
  Lines         962      686      -276     
  Branches       94      107       +13     
===========================================
+ Hits          502      585       +83     
+ Misses        460      101      -359     
Flag Coverage Δ
h5 85.27% <60.00%> (+33.09%) ⬆️
wd-img-cropper 85.27% <60.00%> (?)
wd-upload ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Moonofweisheng
Moonofweisheng merged commit 50782a1 into Moonofweisheng:master Jun 22, 2025
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.

3 participants