@vue/compat 3.2.24 → 3.2.25

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.
@@ -34,7 +34,7 @@ const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomo
34
34
  const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs);
35
35
  /**
36
36
  * Boolean attributes should be included if the value is truthy or ''.
37
- * e.g. <select multiple> compiles to { multiple: '' }
37
+ * e.g. `<select multiple>` compiles to `{ multiple: '' }`
38
38
  */
39
39
  function includeBooleanAttr(value) {
40
40
  return !!value || value === '';
@@ -266,7 +266,7 @@ const isIntegerKey = (key) => isString(key) &&
266
266
  '' + parseInt(key, 10) === key;
267
267
  const isReservedProp = /*#__PURE__*/ makeMap(
268
268
  // the leading comma is intentional so empty string "" is also included
269
- ',key,ref,' +
269
+ ',key,ref,ref_for,ref_key,' +
270
270
  'onVnodeBeforeMount,onVnodeMounted,' +
271
271
  'onVnodeBeforeUpdate,onVnodeUpdated,' +
272
272
  'onVnodeBeforeUnmount,onVnodeUnmounted');
@@ -1361,21 +1361,25 @@ function toRefs(object) {
1361
1361
  return ret;
1362
1362
  }
1363
1363
  class ObjectRefImpl {
1364
- constructor(_object, _key) {
1364
+ constructor(_object, _key, _defaultValue) {
1365
1365
  this._object = _object;
1366
1366
  this._key = _key;
1367
+ this._defaultValue = _defaultValue;
1367
1368
  this.__v_isRef = true;
1368
1369
  }
1369
1370
  get value() {
1370
- return this._object[this._key];
1371
+ const val = this._object[this._key];
1372
+ return val === undefined ? this._defaultValue : val;
1371
1373
  }
1372
1374
  set value(newVal) {
1373
1375
  this._object[this._key] = newVal;
1374
1376
  }
1375
1377
  }
1376
- function toRef(object, key) {
1378
+ function toRef(object, key, defaultValue) {
1377
1379
  const val = object[key];
1378
- return isRef(val) ? val : new ObjectRefImpl(object, key);
1380
+ return isRef(val)
1381
+ ? val
1382
+ : new ObjectRefImpl(object, key, defaultValue);
1379
1383
  }
1380
1384
 
1381
1385
  class ComputedRefImpl {
@@ -1821,11 +1825,6 @@ const deprecationData = {
1821
1825
  `Use "${newHook}" instead.`,
1822
1826
  link: `https://v3.vuejs.org/guide/migration/custom-directives.html`
1823
1827
  },
1824
- ["V_FOR_REF" /* V_FOR_REF */]: {
1825
- message: `Ref usage on v-for no longer creates array ref values in Vue 3. ` +
1826
- `Consider using function refs or refactor to avoid ref usage altogether.`,
1827
- link: `https://v3.vuejs.org/guide/migration/array-refs.html`
1828
- },
1829
1828
  ["V_ON_KEYCODE_MODIFIER" /* V_ON_KEYCODE_MODIFIER */]: {
1830
1829
  message: `Using keyCode as v-on modifier is no longer supported. ` +
1831
1830
  `Use kebab-case key name modifiers instead.`,
@@ -5238,7 +5237,7 @@ function createCompatVue(createApp, createSingletonApp) {
5238
5237
  return vm;
5239
5238
  }
5240
5239
  }
5241
- Vue.version = "3.2.24";
5240
+ Vue.version = "3.2.25";
5242
5241
  Vue.config = singletonApp.config;
5243
5242
  Vue.use = (p, ...options) => {
5244
5243
  if (p && isFunction(p.install)) {
@@ -5589,7 +5588,7 @@ const methodsToPatch = [
5589
5588
  ];
5590
5589
  const patched = new WeakSet();
5591
5590
  function defineReactive(obj, key, val) {
5592
- // it's possible for the orignial object to be mutated after being defined
5591
+ // it's possible for the original object to be mutated after being defined
5593
5592
  // and expecting reactivity... we are covering it here because this seems to
5594
5593
  // be a bit more common.
5595
5594
  if (isObject(val) && !isReactive(val) && !patched.has(val)) {
@@ -5809,6 +5808,102 @@ function createAppAPI(render, hydrate) {
5809
5808
  };
5810
5809
  }
5811
5810
 
5811
+ /**
5812
+ * Function for handling a template ref
5813
+ */
5814
+ function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
5815
+ if (isArray(rawRef)) {
5816
+ rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
5817
+ return;
5818
+ }
5819
+ if (isAsyncWrapper(vnode) && !isUnmount) {
5820
+ // when mounting async components, nothing needs to be done,
5821
+ // because the template ref is forwarded to inner component
5822
+ return;
5823
+ }
5824
+ const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
5825
+ ? getExposeProxy(vnode.component) || vnode.component.proxy
5826
+ : vnode.el;
5827
+ const value = isUnmount ? null : refValue;
5828
+ const { i: owner, r: ref } = rawRef;
5829
+ if (!owner) {
5830
+ warn$1(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
5831
+ `A vnode with ref must be created inside the render function.`);
5832
+ return;
5833
+ }
5834
+ const oldRef = oldRawRef && oldRawRef.r;
5835
+ const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
5836
+ const setupState = owner.setupState;
5837
+ // dynamic ref changed. unset old ref
5838
+ if (oldRef != null && oldRef !== ref) {
5839
+ if (isString(oldRef)) {
5840
+ refs[oldRef] = null;
5841
+ if (hasOwn(setupState, oldRef)) {
5842
+ setupState[oldRef] = null;
5843
+ }
5844
+ }
5845
+ else if (isRef(oldRef)) {
5846
+ oldRef.value = null;
5847
+ }
5848
+ }
5849
+ if (isFunction(ref)) {
5850
+ callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
5851
+ }
5852
+ else {
5853
+ const _isString = isString(ref);
5854
+ const _isRef = isRef(ref);
5855
+ if (_isString || _isRef) {
5856
+ const doSet = () => {
5857
+ if (rawRef.f) {
5858
+ const existing = _isString ? refs[ref] : ref.value;
5859
+ if (isUnmount) {
5860
+ isArray(existing) && remove(existing, refValue);
5861
+ }
5862
+ else {
5863
+ if (!isArray(existing)) {
5864
+ if (_isString) {
5865
+ refs[ref] = [refValue];
5866
+ }
5867
+ else {
5868
+ ref.value = [refValue];
5869
+ if (rawRef.k)
5870
+ refs[rawRef.k] = ref.value;
5871
+ }
5872
+ }
5873
+ else if (!existing.includes(refValue)) {
5874
+ existing.push(refValue);
5875
+ }
5876
+ }
5877
+ }
5878
+ else if (_isString) {
5879
+ refs[ref] = value;
5880
+ if (hasOwn(setupState, ref)) {
5881
+ setupState[ref] = value;
5882
+ }
5883
+ }
5884
+ else if (isRef(ref)) {
5885
+ ref.value = value;
5886
+ if (rawRef.k)
5887
+ refs[rawRef.k] = value;
5888
+ }
5889
+ else {
5890
+ warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
5891
+ }
5892
+ };
5893
+ if (value) {
5894
+ doSet.id = -1;
5895
+ queuePostRenderEffect(doSet, parentSuspense);
5896
+ }
5897
+ else {
5898
+ doSet();
5899
+ }
5900
+ }
5901
+ else {
5902
+ warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
5903
+ }
5904
+ }
5905
+ }
5906
+
5812
5907
  let hasMismatch = false;
5813
5908
  const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
5814
5909
  const isComment = (node) => node.nodeType === 8 /* COMMENT */;
@@ -6170,44 +6265,6 @@ function isSupported() {
6170
6265
  return supported;
6171
6266
  }
6172
6267
 
6173
- function convertLegacyRefInFor(vnode) {
6174
- // refInFor
6175
- if (vnode.props && vnode.props.refInFor) {
6176
- delete vnode.props.refInFor;
6177
- if (vnode.ref) {
6178
- if (isArray(vnode.ref)) {
6179
- vnode.ref.forEach(r => (r.f = true));
6180
- }
6181
- else {
6182
- vnode.ref.f = true;
6183
- }
6184
- }
6185
- }
6186
- }
6187
- function registerLegacyRef(refs, key, value, owner, isInFor, isUnmount) {
6188
- const existing = refs[key];
6189
- if (isUnmount) {
6190
- if (isArray(existing)) {
6191
- remove(existing, value);
6192
- }
6193
- else {
6194
- refs[key] = null;
6195
- }
6196
- }
6197
- else if (isInFor) {
6198
- warnDeprecation("V_FOR_REF" /* V_FOR_REF */, owner);
6199
- if (!isArray(existing)) {
6200
- refs[key] = [value];
6201
- }
6202
- else if (!existing.includes(value)) {
6203
- existing.push(value);
6204
- }
6205
- }
6206
- else {
6207
- refs[key] = value;
6208
- }
6209
- }
6210
-
6211
6268
  const queuePostRenderEffect = queueEffectWithSuspense
6212
6269
  ;
6213
6270
  /**
@@ -6479,12 +6536,15 @@ function baseCreateRenderer(options, createHydrationFns) {
6479
6536
  const oldProps = n1.props || EMPTY_OBJ;
6480
6537
  const newProps = n2.props || EMPTY_OBJ;
6481
6538
  let vnodeHook;
6539
+ // disable recurse in beforeUpdate hooks
6540
+ parentComponent && toggleRecurse(parentComponent, false);
6482
6541
  if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
6483
6542
  invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
6484
6543
  }
6485
6544
  if (dirs) {
6486
6545
  invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
6487
6546
  }
6547
+ parentComponent && toggleRecurse(parentComponent, true);
6488
6548
  if (isHmrUpdating) {
6489
6549
  // HMR updated, force full diff
6490
6550
  patchFlag = 0;
@@ -6768,7 +6828,7 @@ function baseCreateRenderer(options, createHydrationFns) {
6768
6828
  const { el, props } = initialVNode;
6769
6829
  const { bm, m, parent } = instance;
6770
6830
  const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
6771
- effect.allowRecurse = false;
6831
+ toggleRecurse(instance, false);
6772
6832
  // beforeMount hook
6773
6833
  if (bm) {
6774
6834
  invokeArrayFns(bm);
@@ -6781,7 +6841,7 @@ function baseCreateRenderer(options, createHydrationFns) {
6781
6841
  if (isCompatEnabled("INSTANCE_EVENT_HOOKS" /* INSTANCE_EVENT_HOOKS */, instance)) {
6782
6842
  instance.emit('hook:beforeMount');
6783
6843
  }
6784
- effect.allowRecurse = true;
6844
+ toggleRecurse(instance, true);
6785
6845
  if (el && hydrateNode) {
6786
6846
  // vnode has adopted host node - perform hydration instead of mount.
6787
6847
  const hydrateSubTree = () => {
@@ -6869,7 +6929,7 @@ function baseCreateRenderer(options, createHydrationFns) {
6869
6929
  pushWarningContext(next || instance.vnode);
6870
6930
  }
6871
6931
  // Disallow component effect recursion during pre-lifecycle hooks.
6872
- effect.allowRecurse = false;
6932
+ toggleRecurse(instance, false);
6873
6933
  if (next) {
6874
6934
  next.el = vnode.el;
6875
6935
  updateComponentPreRender(instance, next, optimized);
@@ -6888,7 +6948,7 @@ function baseCreateRenderer(options, createHydrationFns) {
6888
6948
  if (isCompatEnabled("INSTANCE_EVENT_HOOKS" /* INSTANCE_EVENT_HOOKS */, instance)) {
6889
6949
  instance.emit('hook:beforeUpdate');
6890
6950
  }
6891
- effect.allowRecurse = true;
6951
+ toggleRecurse(instance, true);
6892
6952
  // render
6893
6953
  {
6894
6954
  startMeasure(instance, `render`);
@@ -6937,13 +6997,13 @@ function baseCreateRenderer(options, createHydrationFns) {
6937
6997
  }
6938
6998
  };
6939
6999
  // create reactive effect for rendering
6940
- const effect = new ReactiveEffect(componentUpdateFn, () => queueJob(instance.update), instance.scope // track it in component's effect scope
6941
- );
7000
+ const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(instance.update), instance.scope // track it in component's effect scope
7001
+ ));
6942
7002
  const update = (instance.update = effect.run.bind(effect));
6943
7003
  update.id = instance.uid;
6944
7004
  // allowRecurse
6945
7005
  // #1801, #2043 component render effects should allow recursive updates
6946
- effect.allowRecurse = update.allowRecurse = true;
7006
+ toggleRecurse(instance, true);
6947
7007
  {
6948
7008
  effect.onTrack = instance.rtc
6949
7009
  ? e => invokeArrayFns(instance.rtc, e)
@@ -7473,88 +7533,8 @@ function baseCreateRenderer(options, createHydrationFns) {
7473
7533
  createApp: createAppAPI(render, hydrate)
7474
7534
  };
7475
7535
  }
7476
- function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
7477
- if (isArray(rawRef)) {
7478
- rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
7479
- return;
7480
- }
7481
- if (isAsyncWrapper(vnode) && !isUnmount) {
7482
- // when mounting async components, nothing needs to be done,
7483
- // because the template ref is forwarded to inner component
7484
- return;
7485
- }
7486
- const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
7487
- ? getExposeProxy(vnode.component) || vnode.component.proxy
7488
- : vnode.el;
7489
- const value = isUnmount ? null : refValue;
7490
- const { i: owner, r: ref } = rawRef;
7491
- if (!owner) {
7492
- warn$1(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
7493
- `A vnode with ref must be created inside the render function.`);
7494
- return;
7495
- }
7496
- const oldRef = oldRawRef && oldRawRef.r;
7497
- const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
7498
- const setupState = owner.setupState;
7499
- // dynamic ref changed. unset old ref
7500
- if (oldRef != null && oldRef !== ref) {
7501
- if (isString(oldRef)) {
7502
- refs[oldRef] = null;
7503
- if (hasOwn(setupState, oldRef)) {
7504
- setupState[oldRef] = null;
7505
- }
7506
- }
7507
- else if (isRef(oldRef)) {
7508
- oldRef.value = null;
7509
- }
7510
- }
7511
- if (isString(ref)) {
7512
- const doSet = () => {
7513
- if (isCompatEnabled("V_FOR_REF" /* V_FOR_REF */, owner)) {
7514
- registerLegacyRef(refs, ref, refValue, owner, rawRef.f, isUnmount);
7515
- }
7516
- else {
7517
- refs[ref] = value;
7518
- }
7519
- if (hasOwn(setupState, ref)) {
7520
- setupState[ref] = value;
7521
- }
7522
- };
7523
- // #1789: for non-null values, set them after render
7524
- // null values means this is unmount and it should not overwrite another
7525
- // ref with the same key
7526
- if (value) {
7527
- doSet.id = -1;
7528
- queuePostRenderEffect(doSet, parentSuspense);
7529
- }
7530
- else {
7531
- doSet();
7532
- }
7533
- }
7534
- else if (isRef(ref)) {
7535
- const doSet = () => {
7536
- ref.value = value;
7537
- };
7538
- if (value) {
7539
- doSet.id = -1;
7540
- queuePostRenderEffect(doSet, parentSuspense);
7541
- }
7542
- else {
7543
- doSet();
7544
- }
7545
- }
7546
- else if (isFunction(ref)) {
7547
- callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
7548
- }
7549
- else {
7550
- warn$1('Invalid template ref type:', value, `(${typeof value})`);
7551
- }
7552
- }
7553
- function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
7554
- callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
7555
- vnode,
7556
- prevVNode
7557
- ]);
7536
+ function toggleRecurse({ effect, update }, allowed) {
7537
+ effect.allowRecurse = update.allowRecurse = allowed;
7558
7538
  }
7559
7539
  /**
7560
7540
  * #1156
@@ -8349,10 +8329,10 @@ const createVNodeWithArgsTransform = (...args) => {
8349
8329
  };
8350
8330
  const InternalObjectKey = `__vInternal`;
8351
8331
  const normalizeKey = ({ key }) => key != null ? key : null;
8352
- const normalizeRef = ({ ref }) => {
8332
+ const normalizeRef = ({ ref, ref_key, ref_for }) => {
8353
8333
  return (ref != null
8354
8334
  ? isString(ref) || isRef(ref) || isFunction(ref)
8355
- ? { i: currentRenderingInstance, r: ref }
8335
+ ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
8356
8336
  : ref
8357
8337
  : null);
8358
8338
  };
@@ -8420,7 +8400,6 @@ function createBaseVNode(type, props = null, children = null, patchFlag = 0, dyn
8420
8400
  }
8421
8401
  {
8422
8402
  convertLegacyVModelProps(vnode);
8423
- convertLegacyRefInFor(vnode);
8424
8403
  defineLegacyVNodeProperties(vnode);
8425
8404
  }
8426
8405
  return vnode;
@@ -8706,6 +8685,12 @@ function mergeProps(...args) {
8706
8685
  }
8707
8686
  }
8708
8687
  return ret;
8688
+ }
8689
+ function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
8690
+ callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
8691
+ vnode,
8692
+ prevVNode
8693
+ ]);
8709
8694
  }
8710
8695
 
8711
8696
  function getCompatChildren(instance) {
@@ -9365,6 +9350,7 @@ function createComponentInstance(vnode, parent, suspense) {
9365
9350
  root: null,
9366
9351
  next: null,
9367
9352
  subTree: null,
9353
+ effect: null,
9368
9354
  update: null,
9369
9355
  scope: new EffectScope(true /* detached */),
9370
9356
  render: null,
@@ -10834,7 +10820,7 @@ function isMemoSame(cached, memo) {
10834
10820
  }
10835
10821
 
10836
10822
  // Core API ------------------------------------------------------------------
10837
- const version = "3.2.24";
10823
+ const version = "3.2.25";
10838
10824
  /**
10839
10825
  * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
10840
10826
  * @internal