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

fix(dialog): destroy未清除滚动锁定class #1666

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

hosein-code
Copy link

@hosein-code hosein-code commented Dec 2, 2024

🤔 这个 PR 的性质是?

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

🔗 相关 Issue

调用Dialog instance destroy方法后未清除滚动锁定class
复现地址:
https://codesandbox.io/p/devbox/y35jmd?embed=1&file=%2Fsrc%2FApp.vue

💡 需求背景和解决方案

问题:当使用Dialog instance的destroy后未清除body上的滚动锁定class

分析:
1、在调用destory时,会触发popup组件中的innerVisible的变更,从而触发Transition的onAfterLeave回调
2、在popup的onAfterLeave回调中会更改popup的wrapperVisible的值并调用props.onClosed方法
3、props.onClosed为Dialog中create函数初始化,create函数中触发了用户传入的onClosed回调和app卸载方法
4、app.unmount时会清除所有副作用并触发组件的onBeforeUnmount钩子函数,导致useLockScroll中watch(shouldLock)副作用函数未执行。而在onBeforeUnmount的钩子函数中,shouldLock(可变)拿到最新的值为fasle,从而未触发unlock方法。

修复思路:
修改影响范围最小化,在create函数的onClosed回调中,将app卸载放在nextTick中,让副作用函数执行后卸载。
image

📝 更新日志

  • fix(dialog): 修正destroy未清除滚动锁定class

  • 本条 PR 不需要纳入 Changelog

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

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

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

Copy link
Contributor

github-actions bot commented Dec 4, 2024

完成

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