@vue/runtime-core 3.4.26 → 3.5.0-alpha.2

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/runtime-core v3.4.26
2
+ * @vue/runtime-core v3.5.0-alpha.2
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -44,7 +44,9 @@ const ErrorCodes = {
44
44
  "ASYNC_COMPONENT_LOADER": 13,
45
45
  "13": "ASYNC_COMPONENT_LOADER",
46
46
  "SCHEDULER": 14,
47
- "14": "SCHEDULER"
47
+ "14": "SCHEDULER",
48
+ "APP_UNMOUNT_CLEANUP": 15,
49
+ "15": "APP_UNMOUNT_CLEANUP"
48
50
  };
49
51
  const ErrorTypeStrings$1 = {
50
52
  ["sp"]: "serverPrefetch hook",
@@ -75,7 +77,8 @@ const ErrorTypeStrings$1 = {
75
77
  [11]: "app warnHandler",
76
78
  [12]: "ref function",
77
79
  [13]: "async component loader",
78
- [14]: "scheduler flush. This is likely a Vue internals bug. Please open an issue at https://github.com/vuejs/core ."
80
+ [14]: "scheduler flush. This is likely a Vue internals bug. Please open an issue at https://github.com/vuejs/core .",
81
+ [15]: "app unmount cleanup function"
79
82
  };
80
83
  function callWithErrorHandling(fn, instance, type, args) {
81
84
  try {
@@ -160,7 +163,7 @@ function findInsertionIndex(id) {
160
163
  const middle = start + end >>> 1;
161
164
  const middleJob = queue[middle];
162
165
  const middleJobId = getId(middleJob);
163
- if (middleJobId < id || middleJobId === id && middleJob.pre) {
166
+ if (middleJobId < id || middleJobId === id && middleJob.flags & 2) {
164
167
  start = middle + 1;
165
168
  } else {
166
169
  end = middle;
@@ -169,15 +172,21 @@ function findInsertionIndex(id) {
169
172
  return start;
170
173
  }
171
174
  function queueJob(job) {
172
- if (!queue.length || !queue.includes(
173
- job,
174
- isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex
175
- )) {
175
+ var _a;
176
+ if (!(job.flags & 1)) {
176
177
  if (job.id == null) {
177
178
  queue.push(job);
179
+ } else if (
180
+ // fast path when the job id is larger than the tail
181
+ !(job.flags & 2) && job.id >= (((_a = queue[queue.length - 1]) == null ? void 0 : _a.id) || 0)
182
+ ) {
183
+ queue.push(job);
178
184
  } else {
179
185
  queue.splice(findInsertionIndex(job.id), 0, job);
180
186
  }
187
+ if (!(job.flags & 4)) {
188
+ job.flags |= 1;
189
+ }
181
190
  queueFlush();
182
191
  }
183
192
  }
@@ -195,11 +204,11 @@ function invalidateJob(job) {
195
204
  }
196
205
  function queuePostFlushCb(cb) {
197
206
  if (!shared.isArray(cb)) {
198
- if (!activePostFlushCbs || !activePostFlushCbs.includes(
199
- cb,
200
- cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex
201
- )) {
207
+ if (!(cb.flags & 1)) {
202
208
  pendingPostFlushCbs.push(cb);
209
+ if (!(cb.flags & 4)) {
210
+ cb.flags |= 1;
211
+ }
203
212
  }
204
213
  } else {
205
214
  pendingPostFlushCbs.push(...cb);
@@ -209,13 +218,14 @@ function queuePostFlushCb(cb) {
209
218
  function flushPreFlushCbs(instance, seen, i = isFlushing ? flushIndex + 1 : 0) {
210
219
  for (; i < queue.length; i++) {
211
220
  const cb = queue[i];
212
- if (cb && cb.pre) {
221
+ if (cb && cb.flags & 2) {
213
222
  if (instance && cb.id !== instance.uid) {
214
223
  continue;
215
224
  }
216
225
  queue.splice(i, 1);
217
226
  i--;
218
227
  cb();
228
+ cb.flags &= ~1;
219
229
  }
220
230
  }
221
231
  }
@@ -232,6 +242,7 @@ function flushPostFlushCbs(seen) {
232
242
  activePostFlushCbs = deduped;
233
243
  for (postFlushIndex = 0; postFlushIndex < activePostFlushCbs.length; postFlushIndex++) {
234
244
  activePostFlushCbs[postFlushIndex]();
245
+ activePostFlushCbs[postFlushIndex].flags &= ~1;
235
246
  }
236
247
  activePostFlushCbs = null;
237
248
  postFlushIndex = 0;
@@ -241,9 +252,11 @@ const getId = (job) => job.id == null ? Infinity : job.id;
241
252
  const comparator = (a, b) => {
242
253
  const diff = getId(a) - getId(b);
243
254
  if (diff === 0) {
244
- if (a.pre && !b.pre)
255
+ const isAPre = a.flags & 2;
256
+ const isBPre = b.flags & 2;
257
+ if (isAPre && !isBPre)
245
258
  return -1;
246
- if (b.pre && !a.pre)
259
+ if (isBPre && !isAPre)
247
260
  return 1;
248
261
  }
249
262
  return diff;
@@ -255,9 +268,10 @@ function flushJobs(seen) {
255
268
  try {
256
269
  for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
257
270
  const job = queue[flushIndex];
258
- if (job && job.active !== false) {
271
+ if (job && !(job.flags & 8)) {
259
272
  if (false) ;
260
273
  callWithErrorHandling(job, null, 14);
274
+ job.flags &= ~1;
261
275
  }
262
276
  }
263
277
  } finally {
@@ -1352,8 +1366,8 @@ function doWatch(source, cb, {
1352
1366
  }
1353
1367
  }
1354
1368
  let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
1355
- const job = () => {
1356
- if (!effect.active || !effect.dirty) {
1369
+ const job = (immediateFirstRun) => {
1370
+ if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
1357
1371
  return;
1358
1372
  }
1359
1373
  if (cb) {
@@ -1374,19 +1388,22 @@ function doWatch(source, cb, {
1374
1388
  effect.run();
1375
1389
  }
1376
1390
  };
1377
- job.allowRecurse = !!cb;
1391
+ if (cb)
1392
+ job.flags |= 4;
1393
+ const effect = new reactivity.ReactiveEffect(getter);
1378
1394
  let scheduler;
1379
1395
  if (flush === "sync") {
1396
+ effect.flags |= 64;
1380
1397
  scheduler = job;
1381
1398
  } else if (flush === "post") {
1382
1399
  scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
1383
1400
  } else {
1384
- job.pre = true;
1401
+ job.flags |= 2;
1385
1402
  if (instance)
1386
1403
  job.id = instance.uid;
1387
1404
  scheduler = () => queueJob(job);
1388
1405
  }
1389
- const effect = new reactivity.ReactiveEffect(getter, shared.NOOP, scheduler);
1406
+ effect.scheduler = scheduler;
1390
1407
  const scope = reactivity.getCurrentScope();
1391
1408
  const unwatch = () => {
1392
1409
  effect.stop();
@@ -1396,7 +1413,7 @@ function doWatch(source, cb, {
1396
1413
  };
1397
1414
  if (cb) {
1398
1415
  if (immediate) {
1399
- job();
1416
+ job(true);
1400
1417
  } else {
1401
1418
  oldValue = effect.run();
1402
1419
  }
@@ -1566,21 +1583,13 @@ const BaseTransitionImpl = {
1566
1583
  if (!children || !children.length) {
1567
1584
  return;
1568
1585
  }
1569
- let child = children[0];
1570
- if (children.length > 1) {
1571
- for (const c of children) {
1572
- if (c.type !== Comment) {
1573
- child = c;
1574
- break;
1575
- }
1576
- }
1577
- }
1586
+ const child = findNonCommentChild(children);
1578
1587
  const rawProps = reactivity.toRaw(props);
1579
1588
  const { mode } = rawProps;
1580
1589
  if (state.isLeaving) {
1581
1590
  return emptyPlaceholder(child);
1582
1591
  }
1583
- const innerChild = getKeepAliveChild(child);
1592
+ const innerChild = getInnerChild$1(child);
1584
1593
  if (!innerChild) {
1585
1594
  return emptyPlaceholder(child);
1586
1595
  }
@@ -1592,7 +1601,7 @@ const BaseTransitionImpl = {
1592
1601
  );
1593
1602
  setTransitionHooks(innerChild, enterHooks);
1594
1603
  const oldChild = instance.subTree;
1595
- const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
1604
+ const oldInnerChild = oldChild && getInnerChild$1(oldChild);
1596
1605
  if (oldInnerChild && oldInnerChild.type !== Comment && !isSameVNodeType(innerChild, oldInnerChild)) {
1597
1606
  const leavingHooks = resolveTransitionHooks(
1598
1607
  oldInnerChild,
@@ -1605,8 +1614,7 @@ const BaseTransitionImpl = {
1605
1614
  state.isLeaving = true;
1606
1615
  leavingHooks.afterLeave = () => {
1607
1616
  state.isLeaving = false;
1608
- if (instance.update.active !== false) {
1609
- instance.effect.dirty = true;
1617
+ if (!(instance.job.flags & 8)) {
1610
1618
  instance.update();
1611
1619
  }
1612
1620
  };
@@ -1631,6 +1639,18 @@ const BaseTransitionImpl = {
1631
1639
  };
1632
1640
  }
1633
1641
  };
1642
+ function findNonCommentChild(children) {
1643
+ let child = children[0];
1644
+ if (children.length > 1) {
1645
+ for (const c of children) {
1646
+ if (c.type !== Comment) {
1647
+ child = c;
1648
+ break;
1649
+ }
1650
+ }
1651
+ }
1652
+ return child;
1653
+ }
1634
1654
  const BaseTransition = BaseTransitionImpl;
1635
1655
  function getLeavingNodesForType(state, vnode) {
1636
1656
  const { leavingVNodes } = state;
@@ -1785,8 +1805,11 @@ function emptyPlaceholder(vnode) {
1785
1805
  return vnode;
1786
1806
  }
1787
1807
  }
1788
- function getKeepAliveChild(vnode) {
1808
+ function getInnerChild$1(vnode) {
1789
1809
  if (!isKeepAlive(vnode)) {
1810
+ if (isTeleport(vnode.type) && vnode.children) {
1811
+ return findNonCommentChild(vnode.children);
1812
+ }
1790
1813
  return vnode;
1791
1814
  }
1792
1815
  const { shapeFlag, children } = vnode;
@@ -1944,7 +1967,6 @@ function defineAsyncComponent(source) {
1944
1967
  load().then(() => {
1945
1968
  loaded.value = true;
1946
1969
  if (instance.parent && isKeepAlive(instance.parent.vnode)) {
1947
- instance.parent.effect.dirty = true;
1948
1970
  queueJob(instance.parent.update);
1949
1971
  }
1950
1972
  }).catch((err) => {
@@ -2258,10 +2280,20 @@ function onErrorCaptured(hook, target = currentInstance) {
2258
2280
  function renderList(source, renderItem, cache, index) {
2259
2281
  let ret;
2260
2282
  const cached = cache && cache[index];
2261
- if (shared.isArray(source) || shared.isString(source)) {
2283
+ const sourceIsArray = shared.isArray(source);
2284
+ const sourceIsReactiveArray = sourceIsArray && reactivity.isReactive(source);
2285
+ if (sourceIsArray || shared.isString(source)) {
2286
+ if (sourceIsReactiveArray) {
2287
+ source = reactivity.shallowReadArray(source);
2288
+ }
2262
2289
  ret = new Array(source.length);
2263
2290
  for (let i = 0, l = source.length; i < l; i++) {
2264
- ret[i] = renderItem(source[i], i, void 0, cached && cached[i]);
2291
+ ret[i] = renderItem(
2292
+ sourceIsReactiveArray ? reactivity.toReactive(source[i]) : source[i],
2293
+ i,
2294
+ void 0,
2295
+ cached && cached[i]
2296
+ );
2265
2297
  }
2266
2298
  } else if (typeof source === "number") {
2267
2299
  ret = new Array(source);
@@ -2383,7 +2415,6 @@ const publicPropertiesMap = (
2383
2415
  $emit: (i) => i.emit,
2384
2416
  $options: (i) => resolveMergedOptions(i) ,
2385
2417
  $forceUpdate: (i) => i.f || (i.f = () => {
2386
- i.effect.dirty = true;
2387
2418
  queueJob(i.update);
2388
2419
  }),
2389
2420
  $nextTick: (i) => i.n || (i.n = nextTick.bind(i.proxy)),
@@ -2960,6 +2991,7 @@ function createAppAPI(render, hydrate) {
2960
2991
  }
2961
2992
  const context = createAppContext();
2962
2993
  const installedPlugins = /* @__PURE__ */ new WeakSet();
2994
+ const pluginCleanupFns = [];
2963
2995
  let isMounted = false;
2964
2996
  const app = context.app = {
2965
2997
  _uid: uid$1++,
@@ -3026,8 +3058,16 @@ function createAppAPI(render, hydrate) {
3026
3058
  return getExposeProxy(vnode.component) || vnode.component.proxy;
3027
3059
  }
3028
3060
  },
3061
+ onUnmount(cleanupFn) {
3062
+ pluginCleanupFns.push(cleanupFn);
3063
+ },
3029
3064
  unmount() {
3030
3065
  if (isMounted) {
3066
+ callWithAsyncErrorHandling(
3067
+ pluginCleanupFns,
3068
+ app._instance,
3069
+ 15
3070
+ );
3031
3071
  render(null, app._container);
3032
3072
  delete app._container.__vue_app__;
3033
3073
  }
@@ -4544,7 +4584,6 @@ function baseCreateRenderer(options, createHydrationFns) {
4544
4584
  } else {
4545
4585
  instance.next = n2;
4546
4586
  invalidateJob(instance.update);
4547
- instance.effect.dirty = true;
4548
4587
  instance.update();
4549
4588
  }
4550
4589
  } else {
@@ -4679,19 +4718,13 @@ function baseCreateRenderer(options, createHydrationFns) {
4679
4718
  }
4680
4719
  }
4681
4720
  };
4682
- const effect = instance.effect = new reactivity.ReactiveEffect(
4683
- componentUpdateFn,
4684
- shared.NOOP,
4685
- () => queueJob(update),
4686
- instance.scope
4687
- // track it in component's effect scope
4688
- );
4689
- const update = instance.update = () => {
4690
- if (effect.dirty) {
4691
- effect.run();
4692
- }
4693
- };
4694
- update.id = instance.uid;
4721
+ instance.scope.on();
4722
+ const effect = instance.effect = new reactivity.ReactiveEffect(componentUpdateFn);
4723
+ instance.scope.off();
4724
+ const update = instance.update = effect.run.bind(effect);
4725
+ const job = instance.job = effect.runIfDirty.bind(effect);
4726
+ job.id = instance.uid;
4727
+ effect.scheduler = () => queueJob(job);
4695
4728
  toggleRecurse(instance, true);
4696
4729
  update();
4697
4730
  };
@@ -5140,13 +5173,13 @@ function baseCreateRenderer(options, createHydrationFns) {
5140
5173
  hostRemove(end);
5141
5174
  };
5142
5175
  const unmountComponent = (instance, parentSuspense, doRemove) => {
5143
- const { bum, scope, update, subTree, um } = instance;
5176
+ const { bum, scope, job, subTree, um } = instance;
5144
5177
  if (bum) {
5145
5178
  shared.invokeArrayFns(bum);
5146
5179
  }
5147
5180
  scope.stop();
5148
- if (update) {
5149
- update.active = false;
5181
+ if (job) {
5182
+ job.flags |= 8;
5150
5183
  unmount(subTree, instance, parentSuspense, doRemove);
5151
5184
  }
5152
5185
  if (um) {
@@ -5229,8 +5262,14 @@ function baseCreateRenderer(options, createHydrationFns) {
5229
5262
  function resolveChildrenNamespace({ type, props }, currentNamespace) {
5230
5263
  return currentNamespace === "svg" && type === "foreignObject" || currentNamespace === "mathml" && type === "annotation-xml" && props && props.encoding && props.encoding.includes("html") ? void 0 : currentNamespace;
5231
5264
  }
5232
- function toggleRecurse({ effect, update }, allowed) {
5233
- effect.allowRecurse = update.allowRecurse = allowed;
5265
+ function toggleRecurse({ effect, job }, allowed) {
5266
+ if (allowed) {
5267
+ effect.flags |= 32;
5268
+ job.flags |= 4;
5269
+ } else {
5270
+ effect.flags &= ~32;
5271
+ job.flags &= ~4;
5272
+ }
5234
5273
  }
5235
5274
  function needTransition(parentSuspense, transition) {
5236
5275
  return (!parentSuspense || parentSuspense && !parentSuspense.pendingBranch) && transition && !transition.persisted;
@@ -5910,6 +5949,7 @@ function createComponentInstance(vnode, parent, suspense) {
5910
5949
  effect: null,
5911
5950
  update: null,
5912
5951
  // will be set synchronously right after creation
5952
+ job: null,
5913
5953
  scope: new reactivity.EffectScope(
5914
5954
  true
5915
5955
  /* detached */
@@ -6278,7 +6318,7 @@ function isMemoSame(cached, memo) {
6278
6318
  return true;
6279
6319
  }
6280
6320
 
6281
- const version = "3.4.26";
6321
+ const version = "3.5.0-alpha.2";
6282
6322
  const warn$1 = shared.NOOP;
6283
6323
  const ErrorTypeStrings = ErrorTypeStrings$1 ;
6284
6324
  const devtools = void 0;