@mpxjs/core 2.9.32 → 2.9.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.9.32",
3
+ "version": "2.9.35",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -47,5 +47,5 @@
47
47
  "url": "https://github.com/didi/mpx/issues"
48
48
  },
49
49
  "sideEffects": false,
50
- "gitHead": "61ac5a85a2b75304d8b989d4291b4f606f50d82f"
50
+ "gitHead": "eb9647625e82c7dc7058fa35f5d1fe2233d40142"
51
51
  }
@@ -94,9 +94,26 @@ export default function getRefsMixin () {
94
94
 
95
95
  Object.assign(refsMixin.methods, {
96
96
  _createSelectorQuery (...args) {
97
- const selectorQuery = this._originCreateSelectorQuery(...args)
97
+ let selectorQuery = this._originCreateSelectorQuery(...args)
98
98
  const cbs = []
99
99
 
100
+ if (typeof selectorQuery === 'undefined') {
101
+ // 兜底 selectorQuery 在ali为 undefined 情况
102
+ // 调用 createSelectorQuery时,组件实例已经被销毁,ali this._originCreateSelectorQuery 返回 undefined。导致后续 selectorQuery[name] 报错
103
+ // 方案:对齐微信,微信实例销毁时,其他调用正常,仅 createSelectorQuery.exec 不执行回调
104
+ // 复现:setTimeout 中调用,倒计时未回调时切换页面
105
+ selectorQuery = {}
106
+ // ['boundingClientRect', 'context', 'exec', 'fields', 'in', 'node', 'scrollOffset', 'select', 'selectAll', 'selectViewport', 'toImage']
107
+ const backupMethodKeys = Object.keys(envObj.createSelectorQuery())
108
+ const backupFn = function () {
109
+ return selectorQuery
110
+ }
111
+ backupMethodKeys.forEach(key => {
112
+ selectorQuery[key] = backupFn
113
+ })
114
+ return selectorQuery
115
+ }
116
+
100
117
  proxyMethods.forEach((name) => {
101
118
  const originalMethod = selectorQuery[name]
102
119
  selectorQuery[name] = function (cb = noop) {
@@ -1,61 +1,3 @@
1
- import { EffectScope } from 'vue'
2
- import { hasOwn } from '@mpxjs/utils'
3
- import { PausedState } from '../../helper/const'
4
-
5
- const hackEffectScope = () => {
6
- EffectScope.prototype.pause = function () {
7
- if (this.active) {
8
- let i, l
9
- for (i = 0, l = this.effects.length; i < l; i++) {
10
- const effect = this.effects[i]
11
- // vue2.7中存在对于watcher实例方法的重写(doWatch),因此无法通过修改Watcher.prototype统一实现pause和resume,只能逐个实例修改实现
12
- if (!hasOwn(effect, 'pausedState')) {
13
- effect.pausedState = PausedState.resumed
14
- const rawUpdate = effect.update
15
- effect.update = function () {
16
- if (effect.pausedState !== PausedState.resumed) {
17
- effect.pausedState = PausedState.dirty
18
- } else {
19
- rawUpdate.call(effect)
20
- }
21
- }
22
- }
23
- if (effect.pausedState !== PausedState.dirty) {
24
- effect.pausedState = PausedState.paused
25
- }
26
- }
27
- if (this.scopes) {
28
- for (i = 0, l = this.scopes.length; i < l; i++) {
29
- this.scopes[i].pause()
30
- }
31
- }
32
- }
33
- }
34
-
35
- EffectScope.prototype.resume = function (ignoreDirty = false) {
36
- if (this.active) {
37
- let i, l
38
- for (i = 0, l = this.effects.length; i < l; i++) {
39
- const effect = this.effects[i]
40
- if (hasOwn(effect, 'pausedState')) {
41
- const lastPausedState = effect.pausedState
42
- effect.pausedState = PausedState.resumed
43
- if (!ignoreDirty && lastPausedState === PausedState.dirty) {
44
- effect.update()
45
- }
46
- }
47
- }
48
- if (this.scopes) {
49
- for (i = 0, l = this.scopes.length; i < l; i++) {
50
- this.scopes[i].resume(ignoreDirty)
51
- }
52
- }
53
- }
54
- }
55
- }
56
-
57
- hackEffectScope()
58
-
59
1
  export {
60
2
  // watch
61
3
  watchEffect,
package/src/vuePlugin.js CHANGED
@@ -1,5 +1,60 @@
1
1
  import { walkChildren, parseSelector, error, hasOwn } from '@mpxjs/utils'
2
2
  import { createSelectorQuery, createIntersectionObserver } from '@mpxjs/api-proxy'
3
+ import { EffectScope } from 'vue'
4
+ import { PausedState } from './helper/const'
5
+
6
+ const hackEffectScope = () => {
7
+ EffectScope.prototype.pause = function () {
8
+ if (this.active) {
9
+ let i, l
10
+ for (i = 0, l = this.effects.length; i < l; i++) {
11
+ const effect = this.effects[i]
12
+ // vue2.7中存在对于watcher实例方法的重写(doWatch),因此无法通过修改Watcher.prototype统一实现pause和resume,只能逐个实例修改实现
13
+ if (!hasOwn(effect, 'pausedState')) {
14
+ effect.pausedState = PausedState.resumed
15
+ const rawUpdate = effect.update
16
+ effect.update = function () {
17
+ if (effect.pausedState !== PausedState.resumed) {
18
+ effect.pausedState = PausedState.dirty
19
+ } else {
20
+ rawUpdate.call(effect)
21
+ }
22
+ }
23
+ }
24
+ if (effect.pausedState !== PausedState.dirty) {
25
+ effect.pausedState = PausedState.paused
26
+ }
27
+ }
28
+ if (this.scopes) {
29
+ for (i = 0, l = this.scopes.length; i < l; i++) {
30
+ this.scopes[i].pause()
31
+ }
32
+ }
33
+ }
34
+ }
35
+
36
+ EffectScope.prototype.resume = function (ignoreDirty = false) {
37
+ if (this.active) {
38
+ let i, l
39
+ for (i = 0, l = this.effects.length; i < l; i++) {
40
+ const effect = this.effects[i]
41
+ if (hasOwn(effect, 'pausedState')) {
42
+ const lastPausedState = effect.pausedState
43
+ effect.pausedState = PausedState.resumed
44
+ if (!ignoreDirty && lastPausedState === PausedState.dirty) {
45
+ effect.update()
46
+ }
47
+ }
48
+ }
49
+ if (this.scopes) {
50
+ for (i = 0, l = this.scopes.length; i < l; i++) {
51
+ this.scopes[i].resume(ignoreDirty)
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
57
+
3
58
  const datasetReg = /^data-(.+)$/
4
59
 
5
60
  function collectDataset (attrs) {
@@ -55,4 +110,5 @@ export default function install (Vue) {
55
110
  Vue.prototype.createIntersectionObserver = function (options) {
56
111
  return createIntersectionObserver(this, options)
57
112
  }
113
+ hackEffectScope()
58
114
  }