@vue/runtime-core 3.5.0-beta.2 → 3.5.0-rc.1

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.2
2
+ * @vue/runtime-core v3.5.0-rc.1
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,
@@ -1445,7 +1420,7 @@ function getTransitionRawChildren(children, keepComment = false, parentKey) {
1445
1420
  // @__NO_SIDE_EFFECTS__
1446
1421
  function defineComponent(options, extraOptions) {
1447
1422
  return shared.isFunction(options) ? (
1448
- // #8326: extend call and options.name access are considered side-effects
1423
+ // #8236: extend call and options.name access are considered side-effects
1449
1424
  // by Rollup, so we have to wrap it in a pure-annotated IIFE.
1450
1425
  /* @__PURE__ */ (() => shared.extend({ name: options.name }, extraOptions, { setup: options }))()
1451
1426
  ) : options;
@@ -2572,6 +2547,7 @@ const KeepAliveImpl = {
2572
2547
  );
2573
2548
  const { include, exclude, max } = props;
2574
2549
  if (include && (!name || !matches(include, name)) || exclude && name && matches(exclude, name)) {
2550
+ vnode.shapeFlag &= ~256;
2575
2551
  current = vnode;
2576
2552
  return rawVNode;
2577
2553
  }
@@ -3507,16 +3483,20 @@ function callHook(hook, instance, type) {
3507
3483
  );
3508
3484
  }
3509
3485
  function createWatcher(raw, ctx, publicThis, key) {
3510
- const getter = key.includes(".") ? createPathGetter(publicThis, key) : () => publicThis[key];
3486
+ let getter = key.includes(".") ? createPathGetter(publicThis, key) : () => publicThis[key];
3511
3487
  if (shared.isString(raw)) {
3512
3488
  const handler = ctx[raw];
3513
3489
  if (shared.isFunction(handler)) {
3514
- watch(getter, handler);
3490
+ {
3491
+ watch(getter, handler);
3492
+ }
3515
3493
  } else {
3516
3494
  warn$1(`Invalid watch handler specified by key "${raw}"`, handler);
3517
3495
  }
3518
3496
  } else if (shared.isFunction(raw)) {
3519
- watch(getter, raw.bind(publicThis));
3497
+ {
3498
+ watch(getter, raw.bind(publicThis));
3499
+ }
3520
3500
  } else if (shared.isObject(raw)) {
3521
3501
  if (shared.isArray(raw)) {
3522
3502
  raw.forEach((r) => createWatcher(r, ctx, publicThis, key));
@@ -4754,7 +4734,7 @@ function baseCreateRenderer(options, createHydrationFns) {
4754
4734
  if (subTree.patchFlag > 0 && subTree.patchFlag & 2048) {
4755
4735
  subTree = filterSingleRoot(subTree.children) || subTree;
4756
4736
  }
4757
- if (vnode === subTree) {
4737
+ if (vnode === subTree || isSuspense(subTree.type) && (subTree.ssContent === vnode || subTree.ssFallback === vnode)) {
4758
4738
  const parentVNode = parentComponent.vnode;
4759
4739
  setScopeId(
4760
4740
  el,
@@ -5083,7 +5063,6 @@ function baseCreateRenderer(options, createHydrationFns) {
5083
5063
  return;
5084
5064
  } else {
5085
5065
  instance.next = n2;
5086
- invalidateJob(instance.update);
5087
5066
  instance.update();
5088
5067
  }
5089
5068
  } else {
@@ -5974,7 +5953,6 @@ function watchSyncEffect(effect, options) {
5974
5953
  shared.extend({}, options, { flush: "sync" })
5975
5954
  );
5976
5955
  }
5977
- const INITIAL_WATCHER_VALUE = {};
5978
5956
  function watch(source, cb, options) {
5979
5957
  if (!shared.isFunction(cb)) {
5980
5958
  warn$1(
@@ -5983,21 +5961,8 @@ function watch(source, cb, options) {
5983
5961
  }
5984
5962
  return doWatch(source, cb, options);
5985
5963
  }
5986
- function doWatch(source, cb, {
5987
- immediate,
5988
- deep,
5989
- flush,
5990
- once,
5991
- onTrack,
5992
- onTrigger
5993
- } = shared.EMPTY_OBJ) {
5994
- if (cb && once) {
5995
- const _cb = cb;
5996
- cb = (...args) => {
5997
- _cb(...args);
5998
- watchHandle();
5999
- };
6000
- }
5964
+ function doWatch(source, cb, options = shared.EMPTY_OBJ) {
5965
+ const { immediate, deep, flush, once } = options;
6001
5966
  if (!cb) {
6002
5967
  if (immediate !== void 0) {
6003
5968
  warn$1(
@@ -6015,163 +5980,53 @@ function doWatch(source, cb, {
6015
5980
  );
6016
5981
  }
6017
5982
  }
6018
- const warnInvalidSource = (s) => {
6019
- warn$1(
6020
- `Invalid watch source: `,
6021
- s,
6022
- `A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`
6023
- );
6024
- };
6025
- const instance = currentInstance;
6026
- const reactiveGetter = (source2) => {
6027
- if (deep) return source2;
6028
- if (reactivity.isShallow(source2) || deep === false || deep === 0)
6029
- return traverse(source2, 1);
6030
- return traverse(source2);
6031
- };
6032
- let getter;
6033
- let forceTrigger = false;
6034
- let isMultiSource = false;
6035
- if (reactivity.isRef(source)) {
6036
- getter = () => source.value;
6037
- forceTrigger = reactivity.isShallow(source);
6038
- } else if (reactivity.isReactive(source)) {
6039
- getter = () => reactiveGetter(source);
6040
- forceTrigger = true;
6041
- } else if (shared.isArray(source)) {
6042
- isMultiSource = true;
6043
- forceTrigger = source.some((s) => reactivity.isReactive(s) || reactivity.isShallow(s));
6044
- getter = () => source.map((s) => {
6045
- if (reactivity.isRef(s)) {
6046
- return s.value;
6047
- } else if (reactivity.isReactive(s)) {
6048
- return reactiveGetter(s);
6049
- } else if (shared.isFunction(s)) {
6050
- return callWithErrorHandling(s, instance, 2);
6051
- } else {
6052
- warnInvalidSource(s);
6053
- }
6054
- });
6055
- } else if (shared.isFunction(source)) {
6056
- if (cb) {
6057
- getter = () => callWithErrorHandling(source, instance, 2);
6058
- } else {
6059
- getter = () => {
6060
- if (cleanup) {
6061
- cleanup();
6062
- }
6063
- return callWithAsyncErrorHandling(
6064
- source,
6065
- instance,
6066
- 3,
6067
- [onCleanup]
6068
- );
6069
- };
6070
- }
6071
- } else {
6072
- getter = shared.NOOP;
6073
- warnInvalidSource(source);
6074
- }
6075
- if (cb && deep) {
6076
- const baseGetter = getter;
6077
- const depth = deep === true ? Infinity : deep;
6078
- getter = () => traverse(baseGetter(), depth);
6079
- }
6080
- let cleanup;
6081
- let onCleanup = (fn) => {
6082
- cleanup = effect.onStop = () => {
6083
- callWithErrorHandling(fn, instance, 4);
6084
- cleanup = effect.onStop = void 0;
6085
- };
6086
- };
5983
+ const baseWatchOptions = shared.extend({}, options);
5984
+ baseWatchOptions.onWarn = warn$1;
6087
5985
  let ssrCleanup;
6088
5986
  if (isInSSRComponentSetup) {
6089
- onCleanup = shared.NOOP;
6090
- if (!cb) {
6091
- getter();
6092
- } else if (immediate) {
6093
- callWithAsyncErrorHandling(cb, instance, 3, [
6094
- getter(),
6095
- isMultiSource ? [] : void 0,
6096
- onCleanup
6097
- ]);
6098
- }
6099
5987
  if (flush === "sync") {
6100
5988
  const ctx = useSSRContext();
6101
5989
  ssrCleanup = ctx.__watcherHandles || (ctx.__watcherHandles = []);
5990
+ } else if (!cb || immediate) {
5991
+ baseWatchOptions.once = true;
6102
5992
  } else {
6103
- const watchHandle2 = () => {
5993
+ return {
5994
+ stop: shared.NOOP,
5995
+ resume: shared.NOOP,
5996
+ pause: shared.NOOP
6104
5997
  };
6105
- watchHandle2.stop = shared.NOOP;
6106
- watchHandle2.resume = shared.NOOP;
6107
- watchHandle2.pause = shared.NOOP;
6108
- return watchHandle2;
6109
5998
  }
6110
5999
  }
6111
- let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
6112
- const job = (immediateFirstRun) => {
6113
- if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
6114
- return;
6115
- }
6116
- if (cb) {
6117
- const newValue = effect.run();
6118
- if (deep || forceTrigger || (isMultiSource ? newValue.some((v, i) => shared.hasChanged(v, oldValue[i])) : shared.hasChanged(newValue, oldValue)) || false) {
6119
- if (cleanup) {
6120
- cleanup();
6121
- }
6122
- callWithAsyncErrorHandling(cb, instance, 3, [
6123
- newValue,
6124
- // pass undefined as the old value when it's changed for the first time
6125
- oldValue === INITIAL_WATCHER_VALUE ? void 0 : isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE ? [] : oldValue,
6126
- onCleanup
6127
- ]);
6128
- oldValue = newValue;
6000
+ const instance = currentInstance;
6001
+ baseWatchOptions.call = (fn, type, args) => callWithAsyncErrorHandling(fn, instance, type, args);
6002
+ let isPre = false;
6003
+ if (flush === "post") {
6004
+ baseWatchOptions.scheduler = (job) => {
6005
+ queuePostRenderEffect(job, instance && instance.suspense);
6006
+ };
6007
+ } else if (flush !== "sync") {
6008
+ isPre = true;
6009
+ baseWatchOptions.scheduler = (job, isFirstRun) => {
6010
+ if (isFirstRun) {
6011
+ job();
6012
+ } else {
6013
+ queueJob(job);
6129
6014
  }
6130
- } else {
6131
- effect.run();
6132
- }
6133
- };
6134
- if (cb) job.flags |= 4;
6135
- const effect = new reactivity.ReactiveEffect(getter);
6136
- let scheduler;
6137
- if (flush === "sync") {
6138
- scheduler = job;
6139
- } else if (flush === "post") {
6140
- scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
6141
- } else {
6142
- job.flags |= 2;
6143
- if (instance) job.id = instance.uid;
6144
- scheduler = () => queueJob(job);
6015
+ };
6145
6016
  }
6146
- effect.scheduler = scheduler;
6147
- const scope = reactivity.getCurrentScope();
6148
- const watchHandle = () => {
6149
- effect.stop();
6150
- if (scope) {
6151
- shared.remove(scope.effects, effect);
6017
+ baseWatchOptions.augmentJob = (job) => {
6018
+ if (cb) {
6019
+ job.flags |= 4;
6152
6020
  }
6153
- };
6154
- watchHandle.pause = effect.pause.bind(effect);
6155
- watchHandle.resume = effect.resume.bind(effect);
6156
- watchHandle.stop = watchHandle;
6157
- {
6158
- effect.onTrack = onTrack;
6159
- effect.onTrigger = onTrigger;
6160
- }
6161
- if (cb) {
6162
- if (immediate) {
6163
- job(true);
6164
- } else {
6165
- oldValue = effect.run();
6021
+ if (isPre) {
6022
+ job.flags |= 2;
6023
+ if (instance) {
6024
+ job.id = instance.uid;
6025
+ job.i = instance;
6026
+ }
6166
6027
  }
6167
- } else if (flush === "post") {
6168
- queuePostRenderEffect(
6169
- effect.run.bind(effect),
6170
- instance && instance.suspense
6171
- );
6172
- } else {
6173
- effect.run();
6174
- }
6028
+ };
6029
+ const watchHandle = reactivity.watch(source, cb, baseWatchOptions);
6175
6030
  if (ssrCleanup) ssrCleanup.push(watchHandle);
6176
6031
  return watchHandle;
6177
6032
  }
@@ -6200,38 +6055,6 @@ function createPathGetter(ctx, path) {
6200
6055
  return cur;
6201
6056
  };
6202
6057
  }
6203
- function traverse(value, depth = Infinity, seen) {
6204
- if (depth <= 0 || !shared.isObject(value) || value["__v_skip"]) {
6205
- return value;
6206
- }
6207
- seen = seen || /* @__PURE__ */ new Set();
6208
- if (seen.has(value)) {
6209
- return value;
6210
- }
6211
- seen.add(value);
6212
- depth--;
6213
- if (reactivity.isRef(value)) {
6214
- traverse(value.value, depth, seen);
6215
- } else if (shared.isArray(value)) {
6216
- for (let i = 0; i < value.length; i++) {
6217
- traverse(value[i], depth, seen);
6218
- }
6219
- } else if (shared.isSet(value) || shared.isMap(value)) {
6220
- value.forEach((v) => {
6221
- traverse(v, depth, seen);
6222
- });
6223
- } else if (shared.isPlainObject(value)) {
6224
- for (const key in value) {
6225
- traverse(value[key], depth, seen);
6226
- }
6227
- for (const key of Object.getOwnPropertySymbols(value)) {
6228
- if (Object.prototype.propertyIsEnumerable.call(value, key)) {
6229
- traverse(value[key], depth, seen);
6230
- }
6231
- }
6232
- }
6233
- return value;
6234
- }
6235
6058
 
6236
6059
  function useModel(props, name, options = shared.EMPTY_OBJ) {
6237
6060
  const i = getCurrentInstance();
@@ -8379,7 +8202,7 @@ function isMemoSame(cached, memo) {
8379
8202
  return true;
8380
8203
  }
8381
8204
 
8382
- const version = "3.5.0-beta.2";
8205
+ const version = "3.5.0-rc.1";
8383
8206
  const warn = warn$1 ;
8384
8207
  const ErrorTypeStrings = ErrorTypeStrings$1 ;
8385
8208
  const devtools = devtools$1 ;
@@ -8407,6 +8230,7 @@ exports.customRef = reactivity.customRef;
8407
8230
  exports.effect = reactivity.effect;
8408
8231
  exports.effectScope = reactivity.effectScope;
8409
8232
  exports.getCurrentScope = reactivity.getCurrentScope;
8233
+ exports.getCurrentWatcher = reactivity.getCurrentWatcher;
8410
8234
  exports.isProxy = reactivity.isProxy;
8411
8235
  exports.isReactive = reactivity.isReactive;
8412
8236
  exports.isReadonly = reactivity.isReadonly;
@@ -8414,6 +8238,7 @@ exports.isRef = reactivity.isRef;
8414
8238
  exports.isShallow = reactivity.isShallow;
8415
8239
  exports.markRaw = reactivity.markRaw;
8416
8240
  exports.onScopeDispose = reactivity.onScopeDispose;
8241
+ exports.onWatcherCleanup = reactivity.onWatcherCleanup;
8417
8242
  exports.proxyRefs = reactivity.proxyRefs;
8418
8243
  exports.reactive = reactivity.reactive;
8419
8244
  exports.readonly = reactivity.readonly;