@vue/reactivity 3.6.0-rc.13 → 3.6.0-rc.15

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.6.0-rc.13
2
+ * @vue/reactivity v3.6.0-rc.15
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -12,13 +12,7 @@ let _vue_shared = require("@vue/shared");
12
12
  const notifyBuffer = [];
13
13
  let batchDepth = 0;
14
14
  let activeSub = void 0;
15
- let runDepth = 0;
16
- function incRunDepth() {
17
- ++runDepth;
18
- }
19
- function decRunDepth() {
20
- --runDepth;
21
- }
15
+ const CHECKING = 512;
22
16
  let globalVersion = 0;
23
17
  let notifyIndex = 0;
24
18
  let notifyBufferLength = 0;
@@ -67,6 +61,7 @@ function unlink(link, sub = link.sub) {
67
61
  const nextDep = link.nextDep;
68
62
  const nextSub = link.nextSub;
69
63
  const prevSub = link.prevSub;
64
+ link.prevDep = link.nextDep = link.prevSub = link.nextSub = void 0;
70
65
  if (nextDep !== void 0) nextDep.prevDep = prevDep;
71
66
  else sub.depsTail = prevDep;
72
67
  if (prevDep !== void 0) prevDep.nextDep = nextDep;
@@ -74,7 +69,7 @@ function unlink(link, sub = link.sub) {
74
69
  if (nextSub !== void 0) nextSub.prevSub = prevSub;
75
70
  else dep.subsTail = prevSub;
76
71
  if (prevSub !== void 0) prevSub.nextSub = nextSub;
77
- else if ((dep.subs = nextSub) === void 0) {
72
+ else if ((dep.subs = nextSub) === void 0 && dep.flags & 1) {
78
73
  let toRemove = dep.deps;
79
74
  if (toRemove !== void 0) {
80
75
  do
@@ -92,14 +87,12 @@ function propagate(link) {
92
87
  const sub = link.sub;
93
88
  let flags = sub.flags;
94
89
  if (flags & 3) {
95
- if (!(flags & 60)) {
96
- sub.flags = flags | 32;
97
- if (runDepth) sub.flags |= 8;
98
- } else if (!(flags & 12)) flags = 0;
90
+ if (!(flags & 44)) sub.flags = flags | 32;
91
+ else if (!(flags & 12)) flags = 0;
99
92
  else if (!(flags & 4)) sub.flags = flags & -9 | 32;
100
93
  else if (!(flags & 48) && isValidLink(link, sub)) {
101
94
  sub.flags = flags | 40;
102
- flags &= 1;
95
+ flags = sub === activeSub || activeSub === void 0 ? 0 : flags & 1;
103
96
  } else flags = 0;
104
97
  if (flags & 2) notifyBuffer[notifyBufferLength++] = sub;
105
98
  if (flags & 1) {
@@ -135,15 +128,18 @@ function propagate(link) {
135
128
  function startTracking(sub) {
136
129
  ++globalVersion;
137
130
  sub.depsTail = void 0;
138
- sub.flags = sub.flags & -57 | 4;
131
+ sub.flags = sub.flags & -569 | 4;
139
132
  return setActiveSub(sub);
140
133
  }
141
134
  function endTracking(sub, prevSub) {
142
135
  activeSub = prevSub;
143
136
  const depsTail = sub.depsTail;
144
137
  let toRemove = depsTail !== void 0 ? depsTail.nextDep : sub.deps;
145
- while (toRemove !== void 0) toRemove = unlink(toRemove, sub);
146
- sub.flags &= -5;
138
+ while (toRemove !== void 0) {
139
+ unlink(toRemove, sub);
140
+ toRemove = depsTail !== void 0 ? depsTail.nextDep : sub.deps;
141
+ }
142
+ if ((sub.flags &= -5) & 8) markRecursed(sub);
147
143
  }
148
144
  function flush() {
149
145
  let hasError = false;
@@ -165,45 +161,67 @@ function flush() {
165
161
  if (hasError) throw error;
166
162
  }
167
163
  function checkDirty(link, sub) {
164
+ try {
165
+ return walkDirty(link, sub);
166
+ } catch (err) {
167
+ markStale(sub);
168
+ throw err;
169
+ }
170
+ }
171
+ function walkDirty(link, sub) {
172
+ const root = sub;
168
173
  let stack;
169
174
  let checkDepth = 0;
175
+ let staleDepth = 0;
176
+ let staleFloor = 0;
170
177
  top: do {
171
178
  const dep = link.dep;
172
179
  const depFlags = dep.flags;
173
180
  let dirty = false;
174
181
  if (sub.flags & 16) dirty = true;
175
182
  else if ((depFlags & 17) === 17) {
176
- const subs = dep.subs;
177
183
  if (dep.update()) {
178
- if (subs.nextSub !== void 0) shallowPropagate(subs);
184
+ const subs = dep.subs;
185
+ if (subs !== void 0 && (subs !== link || subs.nextSub !== void 0)) shallowPropagate(subs);
179
186
  dirty = true;
180
187
  }
181
188
  } else if ((depFlags & 33) === 33) {
182
- stack = {
183
- value: link,
184
- prev: stack
185
- };
186
- link = dep.deps;
187
- sub = dep;
188
- ++checkDepth;
189
- continue;
189
+ const depth = dep === root ? 0 : depFlags & CHECKING ? checkingDepth(dep, stack, checkDepth) : -1;
190
+ if (depth < 0) {
191
+ if (link.nextSub !== void 0 || link.prevSub !== void 0) dep.flags = depFlags | CHECKING;
192
+ stack = {
193
+ value: link,
194
+ prev: stack
195
+ };
196
+ link = dep.deps;
197
+ sub = dep;
198
+ ++checkDepth;
199
+ continue;
200
+ }
201
+ if (depth < checkDepth) {
202
+ staleFloor = staleDepth && staleFloor < depth ? staleFloor : depth;
203
+ staleDepth = checkDepth;
204
+ }
190
205
  }
191
206
  if (!dirty && link.nextDep !== void 0) {
192
207
  link = link.nextDep;
193
208
  continue;
194
209
  }
195
210
  while (checkDepth) {
211
+ const stale = checkDepth === staleDepth;
212
+ if (stale && --staleDepth === staleFloor) staleDepth = 0;
196
213
  --checkDepth;
197
214
  link = stack.value;
198
215
  stack = stack.prev;
199
216
  if (dirty) {
200
- const subs = sub.subs;
201
217
  if (sub.update()) {
202
- if (subs.nextSub !== void 0) shallowPropagate(subs);
218
+ const subs = sub.subs;
219
+ if (subs !== void 0 && (subs !== link || subs.nextSub !== void 0)) shallowPropagate(subs);
203
220
  sub = link.sub;
204
221
  continue;
205
222
  }
206
- } else sub.flags &= -33;
223
+ } else if (stale) sub.flags = sub.flags & -545 | 16;
224
+ else sub.flags &= -545;
207
225
  sub = link.sub;
208
226
  if (link.nextDep !== void 0) {
209
227
  link = link.nextDep;
@@ -211,9 +229,21 @@ function checkDirty(link, sub) {
211
229
  }
212
230
  dirty = false;
213
231
  }
214
- return dirty && !!sub.flags;
232
+ return (dirty || !!(sub.flags & 16)) && !!sub.flags;
215
233
  } while (true);
216
234
  }
235
+ function checkingDepth(dep, stack, depth) {
236
+ for (; stack !== void 0; stack = stack.prev, --depth) if (stack.value.dep === dep) return depth;
237
+ return -1;
238
+ }
239
+ function markStale(sub) {
240
+ const nodes = [sub];
241
+ do {
242
+ sub = nodes.pop();
243
+ sub.flags = sub.flags & -33 | 16;
244
+ for (let link = sub.deps; link !== void 0; link = link.nextDep) if (link.dep.flags & 32) nodes.push(link.dep);
245
+ } while (nodes.length);
246
+ }
217
247
  function shallowPropagate(link) {
218
248
  do {
219
249
  const sub = link.sub;
@@ -231,6 +261,19 @@ function isValidLink(checkLink, sub) {
231
261
  }
232
262
  return false;
233
263
  }
264
+ function markRecursed(sub) {
265
+ const nodes = [sub];
266
+ do {
267
+ sub = nodes.pop();
268
+ for (let link = sub.deps; link !== void 0; link = link.nextDep) {
269
+ const dep = link.dep;
270
+ if ((dep.flags & 40) === 32) {
271
+ dep.flags |= 8;
272
+ nodes.push(dep);
273
+ }
274
+ }
275
+ } while (nodes.length);
276
+ }
234
277
  //#endregion
235
278
  //#region packages/reactivity/src/dep.ts
236
279
  var Dep = class {
@@ -551,7 +594,7 @@ function noTracking(self, method, args = []) {
551
594
  //#endregion
552
595
  //#region packages/reactivity/src/baseHandlers.ts
553
596
  const isNonTrackableKeys = /*@__PURE__*/ (0, _vue_shared.makeMap)(`__proto__,__v_isRef,__isVue`);
554
- const builtInSymbols = new Set(/*@__PURE__*/ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(_vue_shared.isSymbol));
597
+ const builtInSymbols = /*@__PURE__*/ new Set(/*@__PURE__*/ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(_vue_shared.isSymbol));
555
598
  function hasOwnProperty(key) {
556
599
  if (!(0, _vue_shared.isSymbol)(key)) key = String(key);
557
600
  const obj = /* @__PURE__ */ toRaw(this);
@@ -1348,6 +1391,10 @@ var ReactiveEffect = class {
1348
1391
  get active() {
1349
1392
  return !(this.flags & 1024);
1350
1393
  }
1394
+ /** @internal */
1395
+ get running() {
1396
+ return !!(this.flags & 4);
1397
+ }
1351
1398
  pause() {
1352
1399
  this.flags |= 256;
1353
1400
  }
@@ -1361,11 +1408,9 @@ var ReactiveEffect = class {
1361
1408
  if (!this.active) return this.fn();
1362
1409
  cleanup(this);
1363
1410
  const prevSub = startTracking(this);
1364
- incRunDepth();
1365
1411
  try {
1366
1412
  return this.fn();
1367
1413
  } finally {
1368
- decRunDepth();
1369
1414
  endTracking(this, prevSub);
1370
1415
  const flags = this.flags;
1371
1416
  if ((flags & 136) === 136) {
@@ -1388,9 +1433,9 @@ var ReactiveEffect = class {
1388
1433
  if (flags & 16) return true;
1389
1434
  if (flags & 32) {
1390
1435
  if (checkDirty(this.deps, this)) {
1391
- this.flags = flags | 16;
1436
+ if (this.active) this.flags |= 16;
1392
1437
  return true;
1393
- } else this.flags = flags & -33;
1438
+ } else this.flags &= -33;
1394
1439
  }
1395
1440
  return false;
1396
1441
  }
@@ -1401,20 +1446,15 @@ function effect(fn, options) {
1401
1446
  if (options) {
1402
1447
  const { onStop, scheduler } = options;
1403
1448
  if (onStop) {
1404
- options.onStop = void 0;
1405
1449
  const stop = e.stop.bind(e);
1406
1450
  e.stop = () => {
1407
1451
  stop();
1408
1452
  onStop();
1409
1453
  };
1410
1454
  }
1411
- if (scheduler) {
1412
- options.scheduler = void 0;
1413
- e.notify = () => {
1414
- if (!(e.flags & 256)) scheduler();
1415
- };
1416
- }
1417
- (0, _vue_shared.extend)(e, options);
1455
+ if (scheduler) e.notify = () => {
1456
+ if (!(e.flags & 1280)) scheduler();
1457
+ };
1418
1458
  }
1419
1459
  try {
1420
1460
  e.run();
@@ -1525,8 +1565,10 @@ var EffectScope = class {
1525
1565
  const flags = this.flags;
1526
1566
  if (flags & 256) {
1527
1567
  this.flags = flags & -257;
1528
- for (let link = this.deps; link !== void 0; link = link.nextDep) {
1529
- const dep = link.dep;
1568
+ const deps = [];
1569
+ for (let link = this.deps; link !== void 0; link = link.nextDep) deps.push(link.dep);
1570
+ for (let i = 0; i < deps.length; i++) {
1571
+ const dep = deps[i];
1530
1572
  if ("resume" in dep) dep.resume();
1531
1573
  }
1532
1574
  }
@@ -1555,8 +1597,10 @@ var EffectScope = class {
1555
1597
  while (dep !== void 0) {
1556
1598
  const node = dep.dep;
1557
1599
  if ("stop" in node) {
1558
- dep = dep.nextDep;
1600
+ const prev = dep.prevDep;
1559
1601
  node.stop();
1602
+ const next = prev !== void 0 ? prev.nextDep : this.deps;
1603
+ dep = next === dep ? dep.nextDep : next;
1560
1604
  } else dep = unlink(dep, this);
1561
1605
  }
1562
1606
  cleanup(this);
@@ -1597,10 +1641,14 @@ function setCurrentScope(scope) {
1597
1641
  * @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
1598
1642
  */
1599
1643
  function onScopeDispose(fn, failSilently = false) {
1600
- if (activeEffectScope !== void 0) activeEffectScope.cleanups[activeEffectScope.cleanupsLength++] = fn;
1644
+ if (activeEffectScope !== void 0) {
1645
+ if (activeEffectScope.active) activeEffectScope.cleanups[activeEffectScope.cleanupsLength++] = fn;
1646
+ else fn();
1647
+ }
1601
1648
  }
1602
1649
  //#endregion
1603
1650
  //#region packages/reactivity/src/computed.ts
1651
+ const FAILED = 64;
1604
1652
  /**
1605
1653
  * @private exported by @vue/reactivity for Vue core use, but not exported from
1606
1654
  * the main vue package
@@ -1649,14 +1697,31 @@ var ComputedRefImpl = class {
1649
1697
  }
1650
1698
  get value() {
1651
1699
  const flags = this.flags;
1652
- if (flags & 16 || flags & 32 && checkDirty(this.deps, this)) {
1653
- if (this.update()) {
1654
- const subs = this.subs;
1655
- if (subs !== void 0) shallowPropagate(subs);
1656
- }
1657
- } else if (flags & 32) this.flags = flags & -33;
1700
+ try {
1701
+ if (flags & 16 || flags & 32 && checkDirty(this.deps, this)) {
1702
+ if (this.update()) {
1703
+ const subs = this.subs;
1704
+ if (subs !== void 0) shallowPropagate(subs);
1705
+ }
1706
+ } else if (flags & 32) this.flags = flags & -33;
1707
+ } catch (err) {
1708
+ if (activeSub !== void 0) link(this, activeSub);
1709
+ else if (activeEffectScope !== void 0) link(this, activeEffectScope);
1710
+ throw err;
1711
+ }
1658
1712
  if (activeSub !== void 0) link(this, activeSub);
1659
- else if (activeEffectScope !== void 0) link(this, activeEffectScope);
1713
+ else if (activeEffectScope !== void 0) {
1714
+ if (activeEffectScope.active) link(this, activeEffectScope);
1715
+ else if (this.subs === void 0) {
1716
+ let dep = this.deps;
1717
+ if (dep !== void 0) {
1718
+ do
1719
+ dep = unlink(dep, this);
1720
+ while (dep !== void 0);
1721
+ this.flags |= 16;
1722
+ }
1723
+ }
1724
+ }
1660
1725
  return this._value;
1661
1726
  }
1662
1727
  set value(newValue) {
@@ -1667,11 +1732,15 @@ var ComputedRefImpl = class {
1667
1732
  try {
1668
1733
  const oldValue = this._value;
1669
1734
  const newValue = this.fn(oldValue);
1670
- if ((0, _vue_shared.hasChanged)(oldValue, newValue)) {
1735
+ if ((0, _vue_shared.hasChanged)(oldValue, newValue) || this.flags & FAILED) {
1671
1736
  this._value = newValue;
1737
+ this.flags &= -65;
1672
1738
  return true;
1673
1739
  }
1674
1740
  return false;
1741
+ } catch (err) {
1742
+ this.flags |= FAILED;
1743
+ throw err;
1675
1744
  } finally {
1676
1745
  endTracking(this, prevSub);
1677
1746
  }
@@ -1686,7 +1755,9 @@ function computed(getterOrOptions, debugOptions, isSSR = false) {
1686
1755
  getter = getterOrOptions.get;
1687
1756
  setter = getterOrOptions.set;
1688
1757
  }
1689
- return new ComputedRefImpl(getter, setter);
1758
+ const cRef = new ComputedRefImpl(getter, setter);
1759
+ if (isSSR && activeEffectScope !== void 0) link(cRef, activeEffectScope);
1760
+ return cRef;
1690
1761
  }
1691
1762
  //#endregion
1692
1763
  //#region packages/reactivity/src/constants.ts