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(@tarojs/extend): query 判空&抛出异常 #9328

Closed
wants to merge 13 commits into from
3 changes: 2 additions & 1 deletion packages/taro-extend/src/jquery/zepto.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,9 @@ export const Zepto = (function () {
if (!this.length) return null
if (document.documentElement !== this[0] && !$.contains(document.documentElement, this[0])) { return { top: 0, left: 0 } }
if (!isBrowser) {
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
Taro.createSelectorQuery().select('#' + this[0].uid).boundingClientRect(function (rect) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boundingClientRect 的回调要用箭头函数

if (!rect) reject(new Error('offset error: ' + '#' + this[0].uid + ' query fail'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该直接 return,或者把 resolve 放入 else 块中。现在还是会执行 resolve 的。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promise A+ 规范会处理reject后的resolve

resolve({
left: rect.left,
top: rect.top,
Expand Down