@vue/runtime-core 3.5.0-beta.1 → 3.5.0-beta.3

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.5.0-beta.1
2
+ * @vue/runtime-core v3.5.0-beta.3
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -137,12 +137,6 @@ const ErrorCodes = {
137
137
  "0": "SETUP_FUNCTION",
138
138
  "RENDER_FUNCTION": 1,
139
139
  "1": "RENDER_FUNCTION",
140
- "WATCH_GETTER": 2,
141
- "2": "WATCH_GETTER",
142
- "WATCH_CALLBACK": 3,
143
- "3": "WATCH_CALLBACK",
144
- "WATCH_CLEANUP": 4,
145
- "4": "WATCH_CLEANUP",
146
140
  "NATIVE_EVENT_HANDLER": 5,
147
141
  "5": "NATIVE_EVENT_HANDLER",
148
142
  "COMPONENT_EVENT_HANDLER": 6,
@@ -294,7 +288,7 @@ function nextTick(fn) {
294
288
  return fn ? p.then(this ? fn.bind(this) : fn) : p;
295
289
  }
296
290
  function findInsertionIndex(id) {
297
- let start = flushIndex + 1;
291
+ let start = isFlushing ? flushIndex + 1 : 0;
298
292
  let end = queue.length;
299
293
  while (start < end) {
300
294
  const middle = start + end >>> 1;
@@ -310,15 +304,13 @@ function findInsertionIndex(id) {
310
304
  }
311
305
  function queueJob(job) {
312
306
  if (!(job.flags & 1)) {
313
- if (job.id == null) {
314
- queue.push(job);
315
- } else if (
316
- // fast path when the job id is larger than the tail
317
- !(job.flags & 2) && job.id >= (queue[queue.length - 1] && queue[queue.length - 1].id || 0)
318
- ) {
307
+ const jobId = getId(job);
308
+ const lastJob = queue[queue.length - 1];
309
+ if (!lastJob || // fast path when the job id is larger than the tail
310
+ !(job.flags & 2) && jobId >= getId(lastJob)) {
319
311
  queue.push(job);
320
312
  } else {
321
- queue.splice(findInsertionIndex(job.id), 0, job);
313
+ queue.splice(findInsertionIndex(jobId), 0, job);
322
314
  }
323
315
  if (!(job.flags & 4)) {
324
316
  job.flags |= 1;
@@ -332,12 +324,6 @@ function queueFlush() {
332
324
  currentFlushPromise = resolvedPromise.then(flushJobs);
333
325
  }
334
326
  }
335
- function invalidateJob(job) {
336
- const i = queue.indexOf(job);
337
- if (i > flushIndex) {
338
- queue.splice(i, 1);
339
- }
340
- }
341
327
  function queuePostFlushCb(cb) {
342
328
  if (!shared.isArray(cb)) {
343
329
  if (activePostFlushCbs && cb.id === -1) {
@@ -399,24 +385,13 @@ function flushPostFlushCbs(seen) {
399
385
  postFlushIndex = 0;
400
386
  }
401
387
  }
402
- const getId = (job) => job.id == null ? Infinity : job.id;
403
- const comparator = (a, b) => {
404
- const diff = getId(a) - getId(b);
405
- if (diff === 0) {
406
- const isAPre = a.flags & 2;
407
- const isBPre = b.flags & 2;
408
- if (isAPre && !isBPre) return -1;
409
- if (isBPre && !isAPre) return 1;
410
- }
411
- return diff;
412
- };
388
+ const getId = (job) => job.id == null ? job.flags & 2 ? -1 : Infinity : job.id;
413
389
  function flushJobs(seen) {
414
390
  isFlushPending = false;
415
391
  isFlushing = true;
416
392
  {
417
393
  seen = seen || /* @__PURE__ */ new Map();
418
394
  }
419
- queue.sort(comparator);
420
395
  const check = (job) => checkRecursiveUpdates(seen, job) ;
421
396
  try {
422
397
  for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
@@ -744,7 +719,7 @@ function withDirectives(vnode, directives) {
744
719
  };
745
720
  }
746
721
  if (dir.deep) {
747
- traverse(value);
722
+ reactivity.traverse(value);
748
723
  }
749
724
  bindings.push({
750
725
  dir,
@@ -1564,6 +1539,7 @@ const logMismatchError = () => {
1564
1539
  const isSVGContainer = (container) => container.namespaceURI.includes("svg") && container.tagName !== "foreignObject";
1565
1540
  const isMathMLContainer = (container) => container.namespaceURI.includes("MathML");
1566
1541
  const getContainerType = (container) => {
1542
+ if (container.nodeType !== 1) return void 0;
1567
1543
  if (isSVGContainer(container)) return "svg";
1568
1544
  if (isMathMLContainer(container)) return "mathml";
1569
1545
  return void 0;
@@ -2492,7 +2468,7 @@ const KeepAliveImpl = {
2492
2468
  function pruneCache(filter) {
2493
2469
  cache.forEach((vnode, key) => {
2494
2470
  const name = getComponentName(vnode.type);
2495
- if (name && (!filter || !filter(name))) {
2471
+ if (name && !filter(name)) {
2496
2472
  pruneCacheEntry(key);
2497
2473
  }
2498
2474
  });
@@ -2611,6 +2587,7 @@ function matches(pattern, name) {
2611
2587
  } else if (shared.isString(pattern)) {
2612
2588
  return pattern.split(",").includes(name);
2613
2589
  } else if (shared.isRegExp(pattern)) {
2590
+ pattern.lastIndex = 0;
2614
2591
  return pattern.test(name);
2615
2592
  }
2616
2593
  return false;
@@ -3505,16 +3482,20 @@ function callHook(hook, instance, type) {
3505
3482
  );
3506
3483
  }
3507
3484
  function createWatcher(raw, ctx, publicThis, key) {
3508
- const getter = key.includes(".") ? createPathGetter(publicThis, key) : () => publicThis[key];
3485
+ let getter = key.includes(".") ? createPathGetter(publicThis, key) : () => publicThis[key];
3509
3486
  if (shared.isString(raw)) {
3510
3487
  const handler = ctx[raw];
3511
3488
  if (shared.isFunction(handler)) {
3512
- watch(getter, handler);
3489
+ {
3490
+ watch(getter, handler);
3491
+ }
3513
3492
  } else {
3514
3493
  warn$1(`Invalid watch handler specified by key "${raw}"`, handler);
3515
3494
  }
3516
3495
  } else if (shared.isFunction(raw)) {
3517
- watch(getter, raw.bind(publicThis));
3496
+ {
3497
+ watch(getter, raw.bind(publicThis));
3498
+ }
3518
3499
  } else if (shared.isObject(raw)) {
3519
3500
  if (shared.isArray(raw)) {
3520
3501
  raw.forEach((r) => createWatcher(r, ctx, publicThis, key));
@@ -4752,7 +4733,7 @@ function baseCreateRenderer(options, createHydrationFns) {
4752
4733
  if (subTree.patchFlag > 0 && subTree.patchFlag & 2048) {
4753
4734
  subTree = filterSingleRoot(subTree.children) || subTree;
4754
4735
  }
4755
- if (vnode === subTree) {
4736
+ if (vnode === subTree || isSuspense(subTree.type) && (subTree.ssContent === vnode || subTree.ssFallback === vnode)) {
4756
4737
  const parentVNode = parentComponent.vnode;
4757
4738
  setScopeId(
4758
4739
  el,
@@ -5081,7 +5062,6 @@ function baseCreateRenderer(options, createHydrationFns) {
5081
5062
  return;
5082
5063
  } else {
5083
5064
  instance.next = n2;
5084
- invalidateJob(instance.update);
5085
5065
  instance.update();
5086
5066
  }
5087
5067
  } else {
@@ -5972,7 +5952,6 @@ function watchSyncEffect(effect, options) {
5972
5952
  shared.extend({}, options, { flush: "sync" })
5973
5953
  );
5974
5954
  }
5975
- const INITIAL_WATCHER_VALUE = {};
5976
5955
  function watch(source, cb, options) {
5977
5956
  if (!shared.isFunction(cb)) {
5978
5957
  warn$1(
@@ -5981,21 +5960,8 @@ function watch(source, cb, options) {
5981
5960
  }
5982
5961
  return doWatch(source, cb, options);
5983
5962
  }
5984
- function doWatch(source, cb, {
5985
- immediate,
5986
- deep,
5987
- flush,
5988
- once,
5989
- onTrack,
5990
- onTrigger
5991
- } = shared.EMPTY_OBJ) {
5992
- if (cb && once) {
5993
- const _cb = cb;
5994
- cb = (...args) => {
5995
- _cb(...args);
5996
- watchHandle();
5997
- };
5998
- }
5963
+ function doWatch(source, cb, options = shared.EMPTY_OBJ) {
5964
+ const { immediate, deep, flush, once } = options;
5999
5965
  if (!cb) {
6000
5966
  if (immediate !== void 0) {
6001
5967
  warn$1(
@@ -6013,164 +5979,53 @@ function doWatch(source, cb, {
6013
5979
  );
6014
5980
  }
6015
5981
  }
6016
- const warnInvalidSource = (s) => {
6017
- warn$1(
6018
- `Invalid watch source: `,
6019
- s,
6020
- `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
6021
- );
6022
- };
6023
- const instance = currentInstance;
6024
- const reactiveGetter = (source2) => {
6025
- if (deep) return source2;
6026
- if (reactivity.isShallow(source2) || deep === false || deep === 0)
6027
- return traverse(source2, 1);
6028
- return traverse(source2);
6029
- };
6030
- let getter;
6031
- let forceTrigger = false;
6032
- let isMultiSource = false;
6033
- if (reactivity.isRef(source)) {
6034
- getter = () => source.value;
6035
- forceTrigger = reactivity.isShallow(source);
6036
- } else if (reactivity.isReactive(source)) {
6037
- getter = () => reactiveGetter(source);
6038
- forceTrigger = true;
6039
- } else if (shared.isArray(source)) {
6040
- isMultiSource = true;
6041
- forceTrigger = source.some((s) => reactivity.isReactive(s) || reactivity.isShallow(s));
6042
- getter = () => source.map((s) => {
6043
- if (reactivity.isRef(s)) {
6044
- return s.value;
6045
- } else if (reactivity.isReactive(s)) {
6046
- return reactiveGetter(s);
6047
- } else if (shared.isFunction(s)) {
6048
- return callWithErrorHandling(s, instance, 2);
6049
- } else {
6050
- warnInvalidSource(s);
6051
- }
6052
- });
6053
- } else if (shared.isFunction(source)) {
6054
- if (cb) {
6055
- getter = () => callWithErrorHandling(source, instance, 2);
6056
- } else {
6057
- getter = () => {
6058
- if (cleanup) {
6059
- cleanup();
6060
- }
6061
- return callWithAsyncErrorHandling(
6062
- source,
6063
- instance,
6064
- 3,
6065
- [onCleanup]
6066
- );
6067
- };
6068
- }
6069
- } else {
6070
- getter = shared.NOOP;
6071
- warnInvalidSource(source);
6072
- }
6073
- if (cb && deep) {
6074
- const baseGetter = getter;
6075
- const depth = deep === true ? Infinity : deep;
6076
- getter = () => traverse(baseGetter(), depth);
6077
- }
6078
- let cleanup;
6079
- let onCleanup = (fn) => {
6080
- cleanup = effect.onStop = () => {
6081
- callWithErrorHandling(fn, instance, 4);
6082
- cleanup = effect.onStop = void 0;
6083
- };
6084
- };
5982
+ const baseWatchOptions = shared.extend({}, options);
5983
+ baseWatchOptions.onWarn = warn$1;
6085
5984
  let ssrCleanup;
6086
5985
  if (isInSSRComponentSetup) {
6087
- onCleanup = shared.NOOP;
6088
- if (!cb) {
6089
- getter();
6090
- } else if (immediate) {
6091
- callWithAsyncErrorHandling(cb, instance, 3, [
6092
- getter(),
6093
- isMultiSource ? [] : void 0,
6094
- onCleanup
6095
- ]);
6096
- }
6097
5986
  if (flush === "sync") {
6098
5987
  const ctx = useSSRContext();
6099
5988
  ssrCleanup = ctx.__watcherHandles || (ctx.__watcherHandles = []);
5989
+ } else if (!cb || immediate) {
5990
+ baseWatchOptions.once = true;
6100
5991
  } else {
6101
- const watchHandle2 = () => {
5992
+ return {
5993
+ stop: shared.NOOP,
5994
+ resume: shared.NOOP,
5995
+ pause: shared.NOOP
6102
5996
  };
6103
- watchHandle2.stop = shared.NOOP;
6104
- watchHandle2.resume = shared.NOOP;
6105
- watchHandle2.pause = shared.NOOP;
6106
- return watchHandle2;
6107
5997
  }
6108
5998
  }
6109
- let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
6110
- const job = (immediateFirstRun) => {
6111
- if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
6112
- return;
6113
- }
6114
- if (cb) {
6115
- const newValue = effect.run();
6116
- if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => shared.hasChanged(v, oldValue[i])) : shared.hasChanged(newValue, oldValue)) || false) {
6117
- if (cleanup) {
6118
- cleanup();
6119
- }
6120
- callWithAsyncErrorHandling(cb, instance, 3, [
6121
- newValue,
6122
- // pass undefined as the old value when it's changed for the first time
6123
- oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
6124
- onCleanup
6125
- ]);
6126
- oldValue = newValue;
5999
+ const instance = currentInstance;
6000
+ baseWatchOptions.call = (fn, type, args) => callWithAsyncErrorHandling(fn, instance, type, args);
6001
+ let isPre = false;
6002
+ if (flush === "post") {
6003
+ baseWatchOptions.scheduler = (job) => {
6004
+ queuePostRenderEffect(job, instance && instance.suspense);
6005
+ };
6006
+ } else if (flush !== "sync") {
6007
+ isPre = true;
6008
+ baseWatchOptions.scheduler = (job, isFirstRun) => {
6009
+ if (isFirstRun) {
6010
+ job();
6011
+ } else {
6012
+ queueJob(job);
6127
6013
  }
6128
- } else {
6129
- effect.run();
6130
- }
6131
- };
6132
- if (cb) job.flags |= 4;
6133
- const effect = new reactivity.ReactiveEffect(getter);
6134
- let scheduler;
6135
- if (flush === "sync") {
6136
- effect.flags |= 64;
6137
- scheduler = job;
6138
- } else if (flush === "post") {
6139
- scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
6140
- } else {
6141
- job.flags |= 2;
6142
- if (instance) job.id = instance.uid;
6143
- scheduler = () => queueJob(job);
6014
+ };
6144
6015
  }
6145
- effect.scheduler = scheduler;
6146
- const scope = reactivity.getCurrentScope();
6147
- const watchHandle = () => {
6148
- effect.stop();
6149
- if (scope) {
6150
- shared.remove(scope.effects, effect);
6016
+ baseWatchOptions.augmentJob = (job) => {
6017
+ if (cb) {
6018
+ job.flags |= 4;
6151
6019
  }
6152
- };
6153
- watchHandle.pause = effect.pause.bind(effect);
6154
- watchHandle.resume = effect.resume.bind(effect);
6155
- watchHandle.stop = watchHandle;
6156
- {
6157
- effect.onTrack = onTrack;
6158
- effect.onTrigger = onTrigger;
6159
- }
6160
- if (cb) {
6161
- if (immediate) {
6162
- job(true);
6163
- } else {
6164
- oldValue = effect.run();
6020
+ if (isPre) {
6021
+ job.flags |= 2;
6022
+ if (instance) {
6023
+ job.id = instance.uid;
6024
+ job.i = instance;
6025
+ }
6165
6026
  }
6166
- } else if (flush === "post") {
6167
- queuePostRenderEffect(
6168
- effect.run.bind(effect),
6169
- instance && instance.suspense
6170
- );
6171
- } else {
6172
- effect.run();
6173
- }
6027
+ };
6028
+ const watchHandle = reactivity.watch(source, cb, baseWatchOptions);
6174
6029
  if (ssrCleanup) ssrCleanup.push(watchHandle);
6175
6030
  return watchHandle;
6176
6031
  }
@@ -6199,38 +6054,6 @@ function createPathGetter(ctx, path) {
6199
6054
  return cur;
6200
6055
  };
6201
6056
  }
6202
- function traverse(value, depth = Infinity, seen) {
6203
- if (depth <= 0 || !shared.isObject(value) || value["__v_skip"]) {
6204
- return value;
6205
- }
6206
- seen = seen || /* @__PURE__ */ new Set();
6207
- if (seen.has(value)) {
6208
- return value;
6209
- }
6210
- seen.add(value);
6211
- depth--;
6212
- if (reactivity.isRef(value)) {
6213
- traverse(value.value, depth, seen);
6214
- } else if (shared.isArray(value)) {
6215
- for (let i = 0; i < value.length; i++) {
6216
- traverse(value[i], depth, seen);
6217
- }
6218
- } else if (shared.isSet(value) || shared.isMap(value)) {
6219
- value.forEach((v) => {
6220
- traverse(v, depth, seen);
6221
- });
6222
- } else if (shared.isPlainObject(value)) {
6223
- for (const key in value) {
6224
- traverse(value[key], depth, seen);
6225
- }
6226
- for (const key of Object.getOwnPropertySymbols(value)) {
6227
- if (Object.prototype.propertyIsEnumerable.call(value, key)) {
6228
- traverse(value[key], depth, seen);
6229
- }
6230
- }
6231
- }
6232
- return value;
6233
- }
6234
6057
 
6235
6058
  function useModel(props, name, options = shared.EMPTY_OBJ) {
6236
6059
  const i = getCurrentInstance();
@@ -8378,7 +8201,7 @@ function isMemoSame(cached, memo) {
8378
8201
  return true;
8379
8202
  }
8380
8203
 
8381
- const version = "3.5.0-beta.1";
8204
+ const version = "3.5.0-beta.3";
8382
8205
  const warn = warn$1 ;
8383
8206
  const ErrorTypeStrings = ErrorTypeStrings$1 ;
8384
8207
  const devtools = devtools$1 ;
@@ -8406,6 +8229,7 @@ exports.customRef = reactivity.customRef;
8406
8229
  exports.effect = reactivity.effect;
8407
8230
  exports.effectScope = reactivity.effectScope;
8408
8231
  exports.getCurrentScope = reactivity.getCurrentScope;
8232
+ exports.getCurrentWatcher = reactivity.getCurrentWatcher;
8409
8233
  exports.isProxy = reactivity.isProxy;
8410
8234
  exports.isReactive = reactivity.isReactive;
8411
8235
  exports.isReadonly = reactivity.isReadonly;
@@ -8413,6 +8237,7 @@ exports.isRef = reactivity.isRef;
8413
8237
  exports.isShallow = reactivity.isShallow;
8414
8238
  exports.markRaw = reactivity.markRaw;
8415
8239
  exports.onScopeDispose = reactivity.onScopeDispose;
8240
+ exports.onWatcherCleanup = reactivity.onWatcherCleanup;
8416
8241
  exports.proxyRefs = reactivity.proxyRefs;
8417
8242
  exports.reactive = reactivity.reactive;
8418
8243
  exports.readonly = reactivity.readonly;