@vue/reactivity 3.5.12 → 3.5.14

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/reactivity v3.5.12
2
+ * @vue/reactivity v3.5.14
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -21,6 +21,10 @@ class EffectScope {
21
21
  * @internal
22
22
  */
23
23
  this._active = true;
24
+ /**
25
+ * @internal track `on` calls, allow `on` call multiple times
26
+ */
27
+ this._on = 0;
24
28
  /**
25
29
  * @internal
26
30
  */
@@ -91,28 +95,38 @@ class EffectScope {
91
95
  * @internal
92
96
  */
93
97
  on() {
94
- activeEffectScope = this;
98
+ if (++this._on === 1) {
99
+ this.prevScope = activeEffectScope;
100
+ activeEffectScope = this;
101
+ }
95
102
  }
96
103
  /**
97
104
  * This should only be called on non-detached scopes
98
105
  * @internal
99
106
  */
100
107
  off() {
101
- activeEffectScope = this.parent;
108
+ if (this._on > 0 && --this._on === 0) {
109
+ activeEffectScope = this.prevScope;
110
+ this.prevScope = void 0;
111
+ }
102
112
  }
103
113
  stop(fromParent) {
104
114
  if (this._active) {
115
+ this._active = false;
105
116
  let i, l;
106
117
  for (i = 0, l = this.effects.length; i < l; i++) {
107
118
  this.effects[i].stop();
108
119
  }
120
+ this.effects.length = 0;
109
121
  for (i = 0, l = this.cleanups.length; i < l; i++) {
110
122
  this.cleanups[i]();
111
123
  }
124
+ this.cleanups.length = 0;
112
125
  if (this.scopes) {
113
126
  for (i = 0, l = this.scopes.length; i < l; i++) {
114
127
  this.scopes[i].stop(true);
115
128
  }
129
+ this.scopes.length = 0;
116
130
  }
117
131
  if (!this.detached && this.parent && !fromParent) {
118
132
  const last = this.parent.scopes.pop();
@@ -122,7 +136,6 @@ class EffectScope {
122
136
  }
123
137
  }
124
138
  this.parent = void 0;
125
- this._active = false;
126
139
  }
127
140
  }
128
141
  }
@@ -157,7 +170,9 @@ const EffectFlags = {
157
170
  "ALLOW_RECURSE": 32,
158
171
  "32": "ALLOW_RECURSE",
159
172
  "PAUSED": 64,
160
- "64": "PAUSED"
173
+ "64": "PAUSED",
174
+ "EVALUATED": 128,
175
+ "128": "EVALUATED"
161
176
  };
162
177
  const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
163
178
  class ReactiveEffect {
@@ -193,7 +208,7 @@ class ReactiveEffect {
193
208
  }
194
209
  resume() {
195
210
  if (this.flags & 64) {
196
- this.flags &= ~64;
211
+ this.flags &= -65;
197
212
  if (pausedQueueEffects.has(this)) {
198
213
  pausedQueueEffects.delete(this);
199
214
  this.trigger();
@@ -233,7 +248,7 @@ class ReactiveEffect {
233
248
  cleanupDeps(this);
234
249
  activeSub = prevEffect;
235
250
  shouldTrack = prevShouldTrack;
236
- this.flags &= ~2;
251
+ this.flags &= -3;
237
252
  }
238
253
  }
239
254
  stop() {
@@ -244,7 +259,7 @@ class ReactiveEffect {
244
259
  this.deps = this.depsTail = void 0;
245
260
  cleanupEffect(this);
246
261
  this.onStop && this.onStop();
247
- this.flags &= ~1;
262
+ this.flags &= -2;
248
263
  }
249
264
  }
250
265
  trigger() {
@@ -294,7 +309,7 @@ function endBatch() {
294
309
  while (e) {
295
310
  const next = e.next;
296
311
  e.next = void 0;
297
- e.flags &= ~8;
312
+ e.flags &= -9;
298
313
  e = next;
299
314
  }
300
315
  }
@@ -305,7 +320,7 @@ function endBatch() {
305
320
  while (e) {
306
321
  const next = e.next;
307
322
  e.next = void 0;
308
- e.flags &= ~8;
323
+ e.flags &= -9;
309
324
  if (e.flags & 1) {
310
325
  try {
311
326
  ;
@@ -361,17 +376,16 @@ function refreshComputed(computed) {
361
376
  if (computed.flags & 4 && !(computed.flags & 16)) {
362
377
  return;
363
378
  }
364
- computed.flags &= ~16;
379
+ computed.flags &= -17;
365
380
  if (computed.globalVersion === globalVersion) {
366
381
  return;
367
382
  }
368
383
  computed.globalVersion = globalVersion;
369
- const dep = computed.dep;
370
- computed.flags |= 2;
371
- if (dep.version > 0 && !computed.isSSR && computed.deps && !isDirty(computed)) {
372
- computed.flags &= ~2;
384
+ if (!computed.isSSR && computed.flags & 128 && (!computed.deps && !computed._dirty || !isDirty(computed))) {
373
385
  return;
374
386
  }
387
+ computed.flags |= 2;
388
+ const dep = computed.dep;
375
389
  const prevSub = activeSub;
376
390
  const prevShouldTrack = shouldTrack;
377
391
  activeSub = computed;
@@ -380,6 +394,7 @@ function refreshComputed(computed) {
380
394
  prepareDeps(computed);
381
395
  const value = computed.fn(computed._value);
382
396
  if (dep.version === 0 || shared.hasChanged(value, computed._value)) {
397
+ computed.flags |= 128;
383
398
  computed._value = value;
384
399
  dep.version++;
385
400
  }
@@ -390,7 +405,7 @@ function refreshComputed(computed) {
390
405
  activeSub = prevSub;
391
406
  shouldTrack = prevShouldTrack;
392
407
  cleanupDeps(computed);
393
- computed.flags &= ~2;
408
+ computed.flags &= -3;
394
409
  }
395
410
  }
396
411
  function removeSub(link, soft = false) {
@@ -409,7 +424,7 @@ function removeSub(link, soft = false) {
409
424
  if (dep.subs === link) {
410
425
  dep.subs = prevSub;
411
426
  if (!prevSub && dep.computed) {
412
- dep.computed.flags &= ~4;
427
+ dep.computed.flags &= -5;
413
428
  for (let l = dep.computed.deps; l; l = l.nextDep) {
414
429
  removeSub(l, true);
415
430
  }
@@ -917,6 +932,7 @@ class BaseReactiveHandler {
917
932
  this._isShallow = _isShallow;
918
933
  }
919
934
  get(target, key, receiver) {
935
+ if (key === "__v_skip") return target["__v_skip"];
920
936
  const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
921
937
  if (key === "__v_isReactive") {
922
938
  return !isReadonly2;
@@ -1354,14 +1370,14 @@ function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandl
1354
1370
  if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) {
1355
1371
  return target;
1356
1372
  }
1357
- const existingProxy = proxyMap.get(target);
1358
- if (existingProxy) {
1359
- return existingProxy;
1360
- }
1361
1373
  const targetType = getTargetType(target);
1362
1374
  if (targetType === 0 /* INVALID */) {
1363
1375
  return target;
1364
1376
  }
1377
+ const existingProxy = proxyMap.get(target);
1378
+ if (existingProxy) {
1379
+ return existingProxy;
1380
+ }
1365
1381
  const proxy = new Proxy(
1366
1382
  target,
1367
1383
  targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers
@@ -1769,7 +1785,7 @@ function watch(source, cb, options = shared.EMPTY_OBJ) {
1769
1785
  const scope = getCurrentScope();
1770
1786
  const watchHandle = () => {
1771
1787
  effect.stop();
1772
- if (scope) {
1788
+ if (scope && scope.active) {
1773
1789
  shared.remove(scope.effects, effect);
1774
1790
  }
1775
1791
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/reactivity v3.5.12
2
+ * @vue/reactivity v3.5.14
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -17,6 +17,10 @@ class EffectScope {
17
17
  * @internal
18
18
  */
19
19
  this._active = true;
20
+ /**
21
+ * @internal track `on` calls, allow `on` call multiple times
22
+ */
23
+ this._on = 0;
20
24
  /**
21
25
  * @internal
22
26
  */
@@ -85,28 +89,38 @@ class EffectScope {
85
89
  * @internal
86
90
  */
87
91
  on() {
88
- activeEffectScope = this;
92
+ if (++this._on === 1) {
93
+ this.prevScope = activeEffectScope;
94
+ activeEffectScope = this;
95
+ }
89
96
  }
90
97
  /**
91
98
  * This should only be called on non-detached scopes
92
99
  * @internal
93
100
  */
94
101
  off() {
95
- activeEffectScope = this.parent;
102
+ if (this._on > 0 && --this._on === 0) {
103
+ activeEffectScope = this.prevScope;
104
+ this.prevScope = void 0;
105
+ }
96
106
  }
97
107
  stop(fromParent) {
98
108
  if (this._active) {
109
+ this._active = false;
99
110
  let i, l;
100
111
  for (i = 0, l = this.effects.length; i < l; i++) {
101
112
  this.effects[i].stop();
102
113
  }
114
+ this.effects.length = 0;
103
115
  for (i = 0, l = this.cleanups.length; i < l; i++) {
104
116
  this.cleanups[i]();
105
117
  }
118
+ this.cleanups.length = 0;
106
119
  if (this.scopes) {
107
120
  for (i = 0, l = this.scopes.length; i < l; i++) {
108
121
  this.scopes[i].stop(true);
109
122
  }
123
+ this.scopes.length = 0;
110
124
  }
111
125
  if (!this.detached && this.parent && !fromParent) {
112
126
  const last = this.parent.scopes.pop();
@@ -116,7 +130,6 @@ class EffectScope {
116
130
  }
117
131
  }
118
132
  this.parent = void 0;
119
- this._active = false;
120
133
  }
121
134
  }
122
135
  }
@@ -147,7 +160,9 @@ const EffectFlags = {
147
160
  "ALLOW_RECURSE": 32,
148
161
  "32": "ALLOW_RECURSE",
149
162
  "PAUSED": 64,
150
- "64": "PAUSED"
163
+ "64": "PAUSED",
164
+ "EVALUATED": 128,
165
+ "128": "EVALUATED"
151
166
  };
152
167
  const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
153
168
  class ReactiveEffect {
@@ -183,7 +198,7 @@ class ReactiveEffect {
183
198
  }
184
199
  resume() {
185
200
  if (this.flags & 64) {
186
- this.flags &= ~64;
201
+ this.flags &= -65;
187
202
  if (pausedQueueEffects.has(this)) {
188
203
  pausedQueueEffects.delete(this);
189
204
  this.trigger();
@@ -218,7 +233,7 @@ class ReactiveEffect {
218
233
  cleanupDeps(this);
219
234
  activeSub = prevEffect;
220
235
  shouldTrack = prevShouldTrack;
221
- this.flags &= ~2;
236
+ this.flags &= -3;
222
237
  }
223
238
  }
224
239
  stop() {
@@ -229,7 +244,7 @@ class ReactiveEffect {
229
244
  this.deps = this.depsTail = void 0;
230
245
  cleanupEffect(this);
231
246
  this.onStop && this.onStop();
232
- this.flags &= ~1;
247
+ this.flags &= -2;
233
248
  }
234
249
  }
235
250
  trigger() {
@@ -279,7 +294,7 @@ function endBatch() {
279
294
  while (e) {
280
295
  const next = e.next;
281
296
  e.next = void 0;
282
- e.flags &= ~8;
297
+ e.flags &= -9;
283
298
  e = next;
284
299
  }
285
300
  }
@@ -290,7 +305,7 @@ function endBatch() {
290
305
  while (e) {
291
306
  const next = e.next;
292
307
  e.next = void 0;
293
- e.flags &= ~8;
308
+ e.flags &= -9;
294
309
  if (e.flags & 1) {
295
310
  try {
296
311
  ;
@@ -346,17 +361,16 @@ function refreshComputed(computed) {
346
361
  if (computed.flags & 4 && !(computed.flags & 16)) {
347
362
  return;
348
363
  }
349
- computed.flags &= ~16;
364
+ computed.flags &= -17;
350
365
  if (computed.globalVersion === globalVersion) {
351
366
  return;
352
367
  }
353
368
  computed.globalVersion = globalVersion;
354
- const dep = computed.dep;
355
- computed.flags |= 2;
356
- if (dep.version > 0 && !computed.isSSR && computed.deps && !isDirty(computed)) {
357
- computed.flags &= ~2;
369
+ if (!computed.isSSR && computed.flags & 128 && (!computed.deps && !computed._dirty || !isDirty(computed))) {
358
370
  return;
359
371
  }
372
+ computed.flags |= 2;
373
+ const dep = computed.dep;
360
374
  const prevSub = activeSub;
361
375
  const prevShouldTrack = shouldTrack;
362
376
  activeSub = computed;
@@ -365,6 +379,7 @@ function refreshComputed(computed) {
365
379
  prepareDeps(computed);
366
380
  const value = computed.fn(computed._value);
367
381
  if (dep.version === 0 || shared.hasChanged(value, computed._value)) {
382
+ computed.flags |= 128;
368
383
  computed._value = value;
369
384
  dep.version++;
370
385
  }
@@ -375,7 +390,7 @@ function refreshComputed(computed) {
375
390
  activeSub = prevSub;
376
391
  shouldTrack = prevShouldTrack;
377
392
  cleanupDeps(computed);
378
- computed.flags &= ~2;
393
+ computed.flags &= -3;
379
394
  }
380
395
  }
381
396
  function removeSub(link, soft = false) {
@@ -391,7 +406,7 @@ function removeSub(link, soft = false) {
391
406
  if (dep.subs === link) {
392
407
  dep.subs = prevSub;
393
408
  if (!prevSub && dep.computed) {
394
- dep.computed.flags &= ~4;
409
+ dep.computed.flags &= -5;
395
410
  for (let l = dep.computed.deps; l; l = l.nextDep) {
396
411
  removeSub(l, true);
397
412
  }
@@ -855,6 +870,7 @@ class BaseReactiveHandler {
855
870
  this._isShallow = _isShallow;
856
871
  }
857
872
  get(target, key, receiver) {
873
+ if (key === "__v_skip") return target["__v_skip"];
858
874
  const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
859
875
  if (key === "__v_isReactive") {
860
876
  return !isReadonly2;
@@ -1250,14 +1266,14 @@ function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandl
1250
1266
  if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) {
1251
1267
  return target;
1252
1268
  }
1253
- const existingProxy = proxyMap.get(target);
1254
- if (existingProxy) {
1255
- return existingProxy;
1256
- }
1257
1269
  const targetType = getTargetType(target);
1258
1270
  if (targetType === 0 /* INVALID */) {
1259
1271
  return target;
1260
1272
  }
1273
+ const existingProxy = proxyMap.get(target);
1274
+ if (existingProxy) {
1275
+ return existingProxy;
1276
+ }
1261
1277
  const proxy = new Proxy(
1262
1278
  target,
1263
1279
  targetType === 2 /* COLLECTION */ ? collectionHandlers : baseHandlers
@@ -1623,7 +1639,7 @@ function watch(source, cb, options = shared.EMPTY_OBJ) {
1623
1639
  const scope = getCurrentScope();
1624
1640
  const watchHandle = () => {
1625
1641
  effect.stop();
1626
- if (scope) {
1642
+ if (scope && scope.active) {
1627
1643
  shared.remove(scope.effects, effect);
1628
1644
  }
1629
1645
  };
@@ -47,9 +47,9 @@ export type ShallowReactive<T> = T & {
47
47
  [ShallowReactiveMarker]?: true;
48
48
  };
49
49
  /**
50
- * Shallow version of {@link reactive()}.
50
+ * Shallow version of {@link reactive}.
51
51
  *
52
- * Unlike {@link reactive()}, there is no deep conversion: only root-level
52
+ * Unlike {@link reactive}, there is no deep conversion: only root-level
53
53
  * properties are reactive for a shallow reactive object. Property values are
54
54
  * stored and exposed as-is - this also means properties with ref values will
55
55
  * not be automatically unwrapped.
@@ -87,7 +87,7 @@ export type DeepReadonly<T> = T extends Builtin ? T : T extends Map<infer K, inf
87
87
  * the original.
88
88
  *
89
89
  * A readonly proxy is deep: any nested property accessed will be readonly as
90
- * well. It also has the same ref-unwrapping behavior as {@link reactive()},
90
+ * well. It also has the same ref-unwrapping behavior as {@link reactive},
91
91
  * except the unwrapped values will also be made readonly.
92
92
  *
93
93
  * @example
@@ -113,9 +113,9 @@ export type DeepReadonly<T> = T extends Builtin ? T : T extends Map<infer K, inf
113
113
  */
114
114
  export declare function readonly<T extends object>(target: T): DeepReadonly<UnwrapNestedRefs<T>>;
115
115
  /**
116
- * Shallow version of {@link readonly()}.
116
+ * Shallow version of {@link readonly}.
117
117
  *
118
- * Unlike {@link readonly()}, there is no deep conversion: only root-level
118
+ * Unlike {@link readonly}, there is no deep conversion: only root-level
119
119
  * properties are made readonly. Property values are stored and exposed as-is -
120
120
  * this also means properties with ref values will not be automatically
121
121
  * unwrapped.
@@ -144,8 +144,8 @@ export declare function readonly<T extends object>(target: T): DeepReadonly<Unwr
144
144
  */
145
145
  export declare function shallowReadonly<T extends object>(target: T): Readonly<T>;
146
146
  /**
147
- * Checks if an object is a proxy created by {@link reactive()} or
148
- * {@link shallowReactive()} (or {@link ref()} in some cases).
147
+ * Checks if an object is a proxy created by {@link reactive} or
148
+ * {@link shallowReactive} (or {@link ref} in some cases).
149
149
  *
150
150
  * @example
151
151
  * ```js
@@ -167,7 +167,7 @@ export declare function isReactive(value: unknown): boolean;
167
167
  * readonly object can change, but they can't be assigned directly via the
168
168
  * passed object.
169
169
  *
170
- * The proxies created by {@link readonly()} and {@link shallowReadonly()} are
170
+ * The proxies created by {@link readonly} and {@link shallowReadonly} are
171
171
  * both considered readonly, as is a computed ref without a set function.
172
172
  *
173
173
  * @param value - The value to check.
@@ -177,7 +177,7 @@ export declare function isReadonly(value: unknown): boolean;
177
177
  export declare function isShallow(value: unknown): boolean;
178
178
  /**
179
179
  * Checks if an object is a proxy created by {@link reactive},
180
- * {@link readonly}, {@link shallowReactive} or {@link shallowReadonly()}.
180
+ * {@link readonly}, {@link shallowReactive} or {@link shallowReadonly}.
181
181
  *
182
182
  * @param value - The value to check.
183
183
  * @see {@link https://vuejs.org/api/reactivity-utilities.html#isproxy}
@@ -187,8 +187,8 @@ export declare function isProxy(value: any): boolean;
187
187
  * Returns the raw, original object of a Vue-created proxy.
188
188
  *
189
189
  * `toRaw()` can return the original object from proxies created by
190
- * {@link reactive()}, {@link readonly()}, {@link shallowReactive()} or
191
- * {@link shallowReadonly()}.
190
+ * {@link reactive}, {@link readonly}, {@link shallowReactive} or
191
+ * {@link shallowReadonly}.
192
192
  *
193
193
  * This is an escape hatch that can be used to temporarily read without
194
194
  * incurring proxy access / tracking overhead or write without triggering
@@ -225,7 +225,7 @@ export type Raw<T> = T & {
225
225
  * ```
226
226
  *
227
227
  * **Warning:** `markRaw()` together with the shallow APIs such as
228
- * {@link shallowReactive()} allow you to selectively opt-out of the default
228
+ * {@link shallowReactive} allow you to selectively opt-out of the default
229
229
  * deep reactive/readonly conversion and embed raw, non-proxied objects in your
230
230
  * state graph.
231
231
  *
@@ -281,7 +281,8 @@ export declare enum EffectFlags {
281
281
  NOTIFIED = 8,
282
282
  DIRTY = 16,
283
283
  ALLOW_RECURSE = 32,
284
- PAUSED = 64
284
+ PAUSED = 64,
285
+ EVALUATED = 128
285
286
  }
286
287
  /**
287
288
  * Subscriber is a type that tracks (or subscribes to) a list of deps.
@@ -447,7 +448,7 @@ export type ShallowRef<T = any, S = T> = Ref<T, S> & {
447
448
  [ShallowRefMarker]?: true;
448
449
  };
449
450
  /**
450
- * Shallow version of {@link ref()}.
451
+ * Shallow version of {@link ref}.
451
452
  *
452
453
  * @example
453
454
  * ```js
@@ -512,7 +513,7 @@ export type MaybeRefOrGetter<T = any> = MaybeRef<T> | ComputedRef<T> | (() => T)
512
513
  export declare function unref<T>(ref: MaybeRef<T> | ComputedRef<T>): T;
513
514
  /**
514
515
  * Normalizes values / refs / getters to values.
515
- * This is similar to {@link unref()}, except that it also normalizes getters.
516
+ * This is similar to {@link unref}, except that it also normalizes getters.
516
517
  * If the argument is a getter, it will be invoked and its return value will
517
518
  * be returned.
518
519
  *
@@ -554,7 +555,7 @@ export type ToRefs<T = any> = {
554
555
  /**
555
556
  * Converts a reactive object to a plain object where each property of the
556
557
  * resulting object is a ref pointing to the corresponding property of the
557
- * original object. Each individual ref is created using {@link toRef()}.
558
+ * original object. Each individual ref is created using {@link toRef}.
558
559
  *
559
560
  * @param object - Reactive object to be made into an object of linked refs.
560
561
  * @see {@link https://vuejs.org/api/reactivity-utilities.html#torefs}
@@ -672,6 +673,7 @@ export declare class EffectScope {
672
673
  */
673
674
  resume(): void;
674
675
  run<T>(fn: () => T): T | undefined;
676
+ prevScope: EffectScope | undefined;
675
677
  stop(fromParent?: boolean): void;
676
678
  }
677
679
  /**
@@ -752,3 +754,4 @@ export declare function onWatcherCleanup(cleanupFn: () => void, failSilently?: b
752
754
  export declare function watch(source: WatchSource | WatchSource[] | WatchEffect | object, cb?: WatchCallback | null, options?: WatchOptions): WatchHandle;
753
755
  export declare function traverse(value: unknown, depth?: number, seen?: Set<unknown>): unknown;
754
756
 
757
+