@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
  **/
@@ -157,7 +157,9 @@ const ErrorCodes = {
157
157
  "ASYNC_COMPONENT_LOADER": 13,
158
158
  "13": "ASYNC_COMPONENT_LOADER",
159
159
  "SCHEDULER": 14,
160
- "14": "SCHEDULER"
160
+ "14": "SCHEDULER",
161
+ "APP_UNMOUNT_CLEANUP": 15,
162
+ "15": "APP_UNMOUNT_CLEANUP"
161
163
  };
162
164
  const ErrorTypeStrings$1 = {
163
165
  ["sp"]: "serverPrefetch hook",
@@ -188,7 +190,8 @@ const ErrorTypeStrings$1 = {
188
190
  [11]: "app warnHandler",
189
191
  [12]: "ref function",
190
192
  [13]: "async component loader",
191
- [14]: "scheduler flush. This is likely a Vue internals bug. Please open an issue at https://github.com/vuejs/core ."
193
+ [14]: "scheduler flush. This is likely a Vue internals bug. Please open an issue at https://github.com/vuejs/core .",
194
+ [15]: "app unmount cleanup function"
192
195
  };
193
196
  function callWithErrorHandling(fn, instance, type, args) {
194
197
  try {
@@ -290,7 +293,7 @@ function findInsertionIndex(id) {
290
293
  const middle = start + end >>> 1;
291
294
  const middleJob = queue[middle];
292
295
  const middleJobId = getId(middleJob);
293
- if (middleJobId < id || middleJobId === id && middleJob.pre) {
296
+ if (middleJobId < id || middleJobId === id && middleJob.flags & 2) {
294
297
  start = middle + 1;
295
298
  } else {
296
299
  end = middle;
@@ -299,15 +302,21 @@ function findInsertionIndex(id) {
299
302
  return start;
300
303
  }
301
304
  function queueJob(job) {
302
- if (!queue.length || !queue.includes(
303
- job,
304
- isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex
305
- )) {
305
+ var _a;
306
+ if (!(job.flags & 1)) {
306
307
  if (job.id == null) {
307
308
  queue.push(job);
309
+ } else if (
310
+ // fast path when the job id is larger than the tail
311
+ !(job.flags & 2) && job.id >= (((_a = queue[queue.length - 1]) == null ? void 0 : _a.id) || 0)
312
+ ) {
313
+ queue.push(job);
308
314
  } else {
309
315
  queue.splice(findInsertionIndex(job.id), 0, job);
310
316
  }
317
+ if (!(job.flags & 4)) {
318
+ job.flags |= 1;
319
+ }
311
320
  queueFlush();
312
321
  }
313
322
  }
@@ -325,11 +334,11 @@ function invalidateJob(job) {
325
334
  }
326
335
  function queuePostFlushCb(cb) {
327
336
  if (!shared.isArray(cb)) {
328
- if (!activePostFlushCbs || !activePostFlushCbs.includes(
329
- cb,
330
- cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex
331
- )) {
337
+ if (!(cb.flags & 1)) {
332
338
  pendingPostFlushCbs.push(cb);
339
+ if (!(cb.flags & 4)) {
340
+ cb.flags |= 1;
341
+ }
333
342
  }
334
343
  } else {
335
344
  pendingPostFlushCbs.push(...cb);
@@ -342,7 +351,7 @@ function flushPreFlushCbs(instance, seen, i = isFlushing ? flushIndex + 1 : 0) {
342
351
  }
343
352
  for (; i < queue.length; i++) {
344
353
  const cb = queue[i];
345
- if (cb && cb.pre) {
354
+ if (cb && cb.flags & 2) {
346
355
  if (instance && cb.id !== instance.uid) {
347
356
  continue;
348
357
  }
@@ -352,6 +361,7 @@ function flushPreFlushCbs(instance, seen, i = isFlushing ? flushIndex + 1 : 0) {
352
361
  queue.splice(i, 1);
353
362
  i--;
354
363
  cb();
364
+ cb.flags &= ~1;
355
365
  }
356
366
  }
357
367
  }
@@ -374,6 +384,7 @@ function flushPostFlushCbs(seen) {
374
384
  continue;
375
385
  }
376
386
  activePostFlushCbs[postFlushIndex]();
387
+ activePostFlushCbs[postFlushIndex].flags &= ~1;
377
388
  }
378
389
  activePostFlushCbs = null;
379
390
  postFlushIndex = 0;
@@ -383,9 +394,11 @@ const getId = (job) => job.id == null ? Infinity : job.id;
383
394
  const comparator = (a, b) => {
384
395
  const diff = getId(a) - getId(b);
385
396
  if (diff === 0) {
386
- if (a.pre && !b.pre)
397
+ const isAPre = a.flags & 2;
398
+ const isBPre = b.flags & 2;
399
+ if (isAPre && !isBPre)
387
400
  return -1;
388
- if (b.pre && !a.pre)
401
+ if (isBPre && !isAPre)
389
402
  return 1;
390
403
  }
391
404
  return diff;
@@ -401,11 +414,12 @@ function flushJobs(seen) {
401
414
  try {
402
415
  for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
403
416
  const job = queue[flushIndex];
404
- if (job && job.active !== false) {
417
+ if (job && !(job.flags & 8)) {
405
418
  if (check(job)) {
406
419
  continue;
407
420
  }
408
421
  callWithErrorHandling(job, null, 14);
422
+ job.flags &= ~1;
409
423
  }
410
424
  }
411
425
  } finally {
@@ -487,7 +501,6 @@ function rerender(id, newRender) {
487
501
  }
488
502
  instance.renderCache = [];
489
503
  isHmrUpdating = true;
490
- instance.effect.dirty = true;
491
504
  instance.update();
492
505
  isHmrUpdating = false;
493
506
  });
@@ -515,7 +528,6 @@ function reload(id, newComp) {
515
528
  instance.ceReload(newComp.styles);
516
529
  hmrDirtyComponents.delete(oldComp);
517
530
  } else if (instance.parent) {
518
- instance.parent.effect.dirty = true;
519
531
  queueJob(instance.parent.update);
520
532
  } else if (instance.appContext.reload) {
521
533
  instance.appContext.reload();
@@ -1940,8 +1952,8 @@ function doWatch(source, cb, {
1940
1952
  }
1941
1953
  }
1942
1954
  let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
1943
- const job = () => {
1944
- if (!effect.active || !effect.dirty) {
1955
+ const job = (immediateFirstRun) => {
1956
+ if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
1945
1957
  return;
1946
1958
  }
1947
1959
  if (cb) {
@@ -1962,19 +1974,22 @@ function doWatch(source, cb, {
1962
1974
  effect.run();
1963
1975
  }
1964
1976
  };
1965
- job.allowRecurse = !!cb;
1977
+ if (cb)
1978
+ job.flags |= 4;
1979
+ const effect = new reactivity.ReactiveEffect(getter);
1966
1980
  let scheduler;
1967
1981
  if (flush === "sync") {
1982
+ effect.flags |= 64;
1968
1983
  scheduler = job;
1969
1984
  } else if (flush === "post") {
1970
1985
  scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
1971
1986
  } else {
1972
- job.pre = true;
1987
+ job.flags |= 2;
1973
1988
  if (instance)
1974
1989
  job.id = instance.uid;
1975
1990
  scheduler = () => queueJob(job);
1976
1991
  }
1977
- const effect = new reactivity.ReactiveEffect(getter, shared.NOOP, scheduler);
1992
+ effect.scheduler = scheduler;
1978
1993
  const scope = reactivity.getCurrentScope();
1979
1994
  const unwatch = () => {
1980
1995
  effect.stop();
@@ -1988,7 +2003,7 @@ function doWatch(source, cb, {
1988
2003
  }
1989
2004
  if (cb) {
1990
2005
  if (immediate) {
1991
- job();
2006
+ job(true);
1992
2007
  } else {
1993
2008
  oldValue = effect.run();
1994
2009
  }
@@ -2164,22 +2179,7 @@ const BaseTransitionImpl = {
2164
2179
  if (!children || !children.length) {
2165
2180
  return;
2166
2181
  }
2167
- let child = children[0];
2168
- if (children.length > 1) {
2169
- let hasFound = false;
2170
- for (const c of children) {
2171
- if (c.type !== Comment) {
2172
- if (hasFound) {
2173
- warn$1(
2174
- "<transition> can only be used on a single element or component. Use <transition-group> for lists."
2175
- );
2176
- break;
2177
- }
2178
- child = c;
2179
- hasFound = true;
2180
- }
2181
- }
2182
- }
2182
+ const child = findNonCommentChild(children);
2183
2183
  const rawProps = reactivity.toRaw(props);
2184
2184
  const { mode } = rawProps;
2185
2185
  if (mode && mode !== "in-out" && mode !== "out-in" && mode !== "default") {
@@ -2188,7 +2188,7 @@ const BaseTransitionImpl = {
2188
2188
  if (state.isLeaving) {
2189
2189
  return emptyPlaceholder(child);
2190
2190
  }
2191
- const innerChild = getKeepAliveChild(child);
2191
+ const innerChild = getInnerChild$1(child);
2192
2192
  if (!innerChild) {
2193
2193
  return emptyPlaceholder(child);
2194
2194
  }
@@ -2200,7 +2200,7 @@ const BaseTransitionImpl = {
2200
2200
  );
2201
2201
  setTransitionHooks(innerChild, enterHooks);
2202
2202
  const oldChild = instance.subTree;
2203
- const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
2203
+ const oldInnerChild = oldChild && getInnerChild$1(oldChild);
2204
2204
  if (oldInnerChild && oldInnerChild.type !== Comment && !isSameVNodeType(innerChild, oldInnerChild)) {
2205
2205
  const leavingHooks = resolveTransitionHooks(
2206
2206
  oldInnerChild,
@@ -2213,8 +2213,7 @@ const BaseTransitionImpl = {
2213
2213
  state.isLeaving = true;
2214
2214
  leavingHooks.afterLeave = () => {
2215
2215
  state.isLeaving = false;
2216
- if (instance.update.active !== false) {
2217
- instance.effect.dirty = true;
2216
+ if (!(instance.job.flags & 8)) {
2218
2217
  instance.update();
2219
2218
  }
2220
2219
  };
@@ -2239,6 +2238,25 @@ const BaseTransitionImpl = {
2239
2238
  };
2240
2239
  }
2241
2240
  };
2241
+ function findNonCommentChild(children) {
2242
+ let child = children[0];
2243
+ if (children.length > 1) {
2244
+ let hasFound = false;
2245
+ for (const c of children) {
2246
+ if (c.type !== Comment) {
2247
+ if (hasFound) {
2248
+ warn$1(
2249
+ "<transition> can only be used on a single element or component. Use <transition-group> for lists."
2250
+ );
2251
+ break;
2252
+ }
2253
+ child = c;
2254
+ hasFound = true;
2255
+ }
2256
+ }
2257
+ }
2258
+ return child;
2259
+ }
2242
2260
  const BaseTransition = BaseTransitionImpl;
2243
2261
  function getLeavingNodesForType(state, vnode) {
2244
2262
  const { leavingVNodes } = state;
@@ -2393,8 +2411,11 @@ function emptyPlaceholder(vnode) {
2393
2411
  return vnode;
2394
2412
  }
2395
2413
  }
2396
- function getKeepAliveChild(vnode) {
2414
+ function getInnerChild$1(vnode) {
2397
2415
  if (!isKeepAlive(vnode)) {
2416
+ if (isTeleport(vnode.type) && vnode.children) {
2417
+ return findNonCommentChild(vnode.children);
2418
+ }
2398
2419
  return vnode;
2399
2420
  }
2400
2421
  if (vnode.component) {
@@ -2563,7 +2584,6 @@ function defineAsyncComponent(source) {
2563
2584
  load().then(() => {
2564
2585
  loaded.value = true;
2565
2586
  if (instance.parent && isKeepAlive(instance.parent.vnode)) {
2566
- instance.parent.effect.dirty = true;
2567
2587
  queueJob(instance.parent.update);
2568
2588
  }
2569
2589
  }).catch((err) => {
@@ -2894,10 +2914,20 @@ function onErrorCaptured(hook, target = currentInstance) {
2894
2914
  function renderList(source, renderItem, cache, index) {
2895
2915
  let ret;
2896
2916
  const cached = cache && cache[index];
2897
- if (shared.isArray(source) || shared.isString(source)) {
2917
+ const sourceIsArray = shared.isArray(source);
2918
+ const sourceIsReactiveArray = sourceIsArray && reactivity.isReactive(source);
2919
+ if (sourceIsArray || shared.isString(source)) {
2920
+ if (sourceIsReactiveArray) {
2921
+ source = reactivity.shallowReadArray(source);
2922
+ }
2898
2923
  ret = new Array(source.length);
2899
2924
  for (let i = 0, l = source.length; i < l; i++) {
2900
- ret[i] = renderItem(source[i], i, void 0, cached && cached[i]);
2925
+ ret[i] = renderItem(
2926
+ sourceIsReactiveArray ? reactivity.toReactive(source[i]) : source[i],
2927
+ i,
2928
+ void 0,
2929
+ cached && cached[i]
2930
+ );
2901
2931
  }
2902
2932
  } else if (typeof source === "number") {
2903
2933
  if (!Number.isInteger(source)) {
@@ -3032,7 +3062,6 @@ const publicPropertiesMap = (
3032
3062
  $emit: (i) => i.emit,
3033
3063
  $options: (i) => resolveMergedOptions(i) ,
3034
3064
  $forceUpdate: (i) => i.f || (i.f = () => {
3035
- i.effect.dirty = true;
3036
3065
  queueJob(i.update);
3037
3066
  }),
3038
3067
  $nextTick: (i) => i.n || (i.n = nextTick.bind(i.proxy)),
@@ -3827,6 +3856,7 @@ function createAppAPI(render, hydrate) {
3827
3856
  }
3828
3857
  const context = createAppContext();
3829
3858
  const installedPlugins = /* @__PURE__ */ new WeakSet();
3859
+ const pluginCleanupFns = [];
3830
3860
  let isMounted = false;
3831
3861
  const app = context.app = {
3832
3862
  _uid: uid$1++,
@@ -3944,8 +3974,21 @@ If you want to remount the same app, move your app creation logic into a factory
3944
3974
  );
3945
3975
  }
3946
3976
  },
3977
+ onUnmount(cleanupFn) {
3978
+ if (typeof cleanupFn !== "function") {
3979
+ warn$1(
3980
+ `Expected function as first argument to app.onUnmount(), but got ${typeof cleanupFn}`
3981
+ );
3982
+ }
3983
+ pluginCleanupFns.push(cleanupFn);
3984
+ },
3947
3985
  unmount() {
3948
3986
  if (isMounted) {
3987
+ callWithAsyncErrorHandling(
3988
+ pluginCleanupFns,
3989
+ app._instance,
3990
+ 15
3991
+ );
3949
3992
  render(null, app._container);
3950
3993
  {
3951
3994
  app._instance = null;
@@ -4365,7 +4408,9 @@ const isSimpleType = /* @__PURE__ */ shared.makeMap(
4365
4408
  function assertType(value, type) {
4366
4409
  let valid;
4367
4410
  const expectedType = getType(type);
4368
- if (isSimpleType(expectedType)) {
4411
+ if (expectedType === "null") {
4412
+ valid = value === null;
4413
+ } else if (isSimpleType(expectedType)) {
4369
4414
  const t = typeof value;
4370
4415
  valid = t === expectedType.toLowerCase();
4371
4416
  if (!valid && t === "object") {
@@ -4375,8 +4420,6 @@ function assertType(value, type) {
4375
4420
  valid = shared.isObject(value);
4376
4421
  } else if (expectedType === "Array") {
4377
4422
  valid = shared.isArray(value);
4378
- } else if (expectedType === "null") {
4379
- valid = value === null;
4380
4423
  } else {
4381
4424
  valid = value instanceof type;
4382
4425
  }
@@ -5900,7 +5943,6 @@ function baseCreateRenderer(options, createHydrationFns) {
5900
5943
  } else {
5901
5944
  instance.next = n2;
5902
5945
  invalidateJob(instance.update);
5903
- instance.effect.dirty = true;
5904
5946
  instance.update();
5905
5947
  }
5906
5948
  } else {
@@ -6083,24 +6125,18 @@ function baseCreateRenderer(options, createHydrationFns) {
6083
6125
  }
6084
6126
  }
6085
6127
  };
6086
- const effect = instance.effect = new reactivity.ReactiveEffect(
6087
- componentUpdateFn,
6088
- shared.NOOP,
6089
- () => queueJob(update),
6090
- instance.scope
6091
- // track it in component's effect scope
6092
- );
6093
- const update = instance.update = () => {
6094
- if (effect.dirty) {
6095
- effect.run();
6096
- }
6097
- };
6098
- update.id = instance.uid;
6128
+ instance.scope.on();
6129
+ const effect = instance.effect = new reactivity.ReactiveEffect(componentUpdateFn);
6130
+ instance.scope.off();
6131
+ const update = instance.update = effect.run.bind(effect);
6132
+ const job = instance.job = effect.runIfDirty.bind(effect);
6133
+ job.id = instance.uid;
6134
+ effect.scheduler = () => queueJob(job);
6099
6135
  toggleRecurse(instance, true);
6100
6136
  {
6101
6137
  effect.onTrack = instance.rtc ? (e) => shared.invokeArrayFns(instance.rtc, e) : void 0;
6102
6138
  effect.onTrigger = instance.rtg ? (e) => shared.invokeArrayFns(instance.rtg, e) : void 0;
6103
- update.ownerInstance = instance;
6139
+ job.ownerInstance = instance;
6104
6140
  }
6105
6141
  update();
6106
6142
  };
@@ -6567,13 +6603,13 @@ function baseCreateRenderer(options, createHydrationFns) {
6567
6603
  if (instance.type.__hmrId) {
6568
6604
  unregisterHMR(instance);
6569
6605
  }
6570
- const { bum, scope, update, subTree, um } = instance;
6606
+ const { bum, scope, job, subTree, um } = instance;
6571
6607
  if (bum) {
6572
6608
  shared.invokeArrayFns(bum);
6573
6609
  }
6574
6610
  scope.stop();
6575
- if (update) {
6576
- update.active = false;
6611
+ if (job) {
6612
+ job.flags |= 8;
6577
6613
  unmount(subTree, instance, parentSuspense, doRemove);
6578
6614
  }
6579
6615
  if (um) {
@@ -6659,8 +6695,14 @@ function baseCreateRenderer(options, createHydrationFns) {
6659
6695
  function resolveChildrenNamespace({ type, props }, currentNamespace) {
6660
6696
  return currentNamespace === "svg" && type === "foreignObject" || currentNamespace === "mathml" && type === "annotation-xml" && props && props.encoding && props.encoding.includes("html") ? void 0 : currentNamespace;
6661
6697
  }
6662
- function toggleRecurse({ effect, update }, allowed) {
6663
- effect.allowRecurse = update.allowRecurse = allowed;
6698
+ function toggleRecurse({ effect, job }, allowed) {
6699
+ if (allowed) {
6700
+ effect.flags |= 32;
6701
+ job.flags |= 4;
6702
+ } else {
6703
+ effect.flags &= ~32;
6704
+ job.flags &= ~4;
6705
+ }
6664
6706
  }
6665
6707
  function needTransition(parentSuspense, transition) {
6666
6708
  return (!parentSuspense || parentSuspense && !parentSuspense.pendingBranch) && transition && !transition.persisted;
@@ -7400,6 +7442,7 @@ function createComponentInstance(vnode, parent, suspense) {
7400
7442
  effect: null,
7401
7443
  update: null,
7402
7444
  // will be set synchronously right after creation
7445
+ job: null,
7403
7446
  scope: new reactivity.EffectScope(
7404
7447
  true
7405
7448
  /* detached */
@@ -7910,7 +7953,8 @@ function initCustomFormatter() {
7910
7953
  {},
7911
7954
  ["span", vueStyle, genRefFlag(obj)],
7912
7955
  "<",
7913
- formatValue(obj.value),
7956
+ // avoid debugger accessing value affecting behavior
7957
+ formatValue("_value" in obj ? obj._value : obj),
7914
7958
  `>`
7915
7959
  ];
7916
7960
  } else if (reactivity.isReactive(obj)) {
@@ -8090,7 +8134,7 @@ function isMemoSame(cached, memo) {
8090
8134
  return true;
8091
8135
  }
8092
8136
 
8093
- const version = "3.4.26";
8137
+ const version = "3.5.0-alpha.2";
8094
8138
  const warn = warn$1 ;
8095
8139
  const ErrorTypeStrings = ErrorTypeStrings$1 ;
8096
8140
  const devtools = devtools$1 ;