@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 === '';
@@ -267,7 +267,7 @@ const isIntegerKey = (key) => isString(key) &&
267
267
  '' + parseInt(key, 10) === key;
268
268
  const isReservedProp = /*#__PURE__*/ makeMap(
269
269
  // the leading comma is intentional so empty string "" is also included
270
- ',key,ref,' +
270
+ ',key,ref,ref_for,ref_key,' +
271
271
  'onVnodeBeforeMount,onVnodeMounted,' +
272
272
  'onVnodeBeforeUpdate,onVnodeUpdated,' +
273
273
  'onVnodeBeforeUnmount,onVnodeUnmounted');
@@ -1377,21 +1377,25 @@ function toRefs(object) {
1377
1377
  return ret;
1378
1378
  }
1379
1379
  class ObjectRefImpl {
1380
- constructor(_object, _key) {
1380
+ constructor(_object, _key, _defaultValue) {
1381
1381
  this._object = _object;
1382
1382
  this._key = _key;
1383
+ this._defaultValue = _defaultValue;
1383
1384
  this.__v_isRef = true;
1384
1385
  }
1385
1386
  get value() {
1386
- return this._object[this._key];
1387
+ const val = this._object[this._key];
1388
+ return val === undefined ? this._defaultValue : val;
1387
1389
  }
1388
1390
  set value(newVal) {
1389
1391
  this._object[this._key] = newVal;
1390
1392
  }
1391
1393
  }
1392
- function toRef(object, key) {
1394
+ function toRef(object, key, defaultValue) {
1393
1395
  const val = object[key];
1394
- return isRef(val) ? val : new ObjectRefImpl(object, key);
1396
+ return isRef(val)
1397
+ ? val
1398
+ : new ObjectRefImpl(object, key, defaultValue);
1395
1399
  }
1396
1400
 
1397
1401
  class ComputedRefImpl {
@@ -1838,11 +1842,6 @@ const deprecationData = {
1838
1842
  `Use "${newHook}" instead.`,
1839
1843
  link: `https://v3.vuejs.org/guide/migration/custom-directives.html`
1840
1844
  },
1841
- ["V_FOR_REF" /* V_FOR_REF */]: {
1842
- message: `Ref usage on v-for no longer creates array ref values in Vue 3. ` +
1843
- `Consider using function refs or refactor to avoid ref usage altogether.`,
1844
- link: `https://v3.vuejs.org/guide/migration/array-refs.html`
1845
- },
1846
1845
  ["V_ON_KEYCODE_MODIFIER" /* V_ON_KEYCODE_MODIFIER */]: {
1847
1846
  message: `Using keyCode as v-on modifier is no longer supported. ` +
1848
1847
  `Use kebab-case key name modifiers instead.`,
@@ -5269,7 +5268,7 @@ function createCompatVue(createApp, createSingletonApp) {
5269
5268
  return vm;
5270
5269
  }
5271
5270
  }
5272
- Vue.version = "3.2.24";
5271
+ Vue.version = "3.2.25";
5273
5272
  Vue.config = singletonApp.config;
5274
5273
  Vue.use = (p, ...options) => {
5275
5274
  if (p && isFunction(p.install)) {
@@ -5622,7 +5621,7 @@ const methodsToPatch = [
5622
5621
  ];
5623
5622
  const patched = new WeakSet();
5624
5623
  function defineReactive(obj, key, val) {
5625
- // it's possible for the orignial object to be mutated after being defined
5624
+ // it's possible for the original object to be mutated after being defined
5626
5625
  // and expecting reactivity... we are covering it here because this seems to
5627
5626
  // be a bit more common.
5628
5627
  if (isObject(val) && !isReactive(val) && !patched.has(val)) {
@@ -5845,6 +5844,102 @@ function createAppAPI(render, hydrate) {
5845
5844
  };
5846
5845
  }
5847
5846
 
5847
+ /**
5848
+ * Function for handling a template ref
5849
+ */
5850
+ function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
5851
+ if (isArray(rawRef)) {
5852
+ rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
5853
+ return;
5854
+ }
5855
+ if (isAsyncWrapper(vnode) && !isUnmount) {
5856
+ // when mounting async components, nothing needs to be done,
5857
+ // because the template ref is forwarded to inner component
5858
+ return;
5859
+ }
5860
+ const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
5861
+ ? getExposeProxy(vnode.component) || vnode.component.proxy
5862
+ : vnode.el;
5863
+ const value = isUnmount ? null : refValue;
5864
+ const { i: owner, r: ref } = rawRef;
5865
+ if ((process.env.NODE_ENV !== 'production') && !owner) {
5866
+ warn$1(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
5867
+ `A vnode with ref must be created inside the render function.`);
5868
+ return;
5869
+ }
5870
+ const oldRef = oldRawRef && oldRawRef.r;
5871
+ const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
5872
+ const setupState = owner.setupState;
5873
+ // dynamic ref changed. unset old ref
5874
+ if (oldRef != null && oldRef !== ref) {
5875
+ if (isString(oldRef)) {
5876
+ refs[oldRef] = null;
5877
+ if (hasOwn(setupState, oldRef)) {
5878
+ setupState[oldRef] = null;
5879
+ }
5880
+ }
5881
+ else if (isRef(oldRef)) {
5882
+ oldRef.value = null;
5883
+ }
5884
+ }
5885
+ if (isFunction(ref)) {
5886
+ callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
5887
+ }
5888
+ else {
5889
+ const _isString = isString(ref);
5890
+ const _isRef = isRef(ref);
5891
+ if (_isString || _isRef) {
5892
+ const doSet = () => {
5893
+ if (rawRef.f) {
5894
+ const existing = _isString ? refs[ref] : ref.value;
5895
+ if (isUnmount) {
5896
+ isArray(existing) && remove(existing, refValue);
5897
+ }
5898
+ else {
5899
+ if (!isArray(existing)) {
5900
+ if (_isString) {
5901
+ refs[ref] = [refValue];
5902
+ }
5903
+ else {
5904
+ ref.value = [refValue];
5905
+ if (rawRef.k)
5906
+ refs[rawRef.k] = ref.value;
5907
+ }
5908
+ }
5909
+ else if (!existing.includes(refValue)) {
5910
+ existing.push(refValue);
5911
+ }
5912
+ }
5913
+ }
5914
+ else if (_isString) {
5915
+ refs[ref] = value;
5916
+ if (hasOwn(setupState, ref)) {
5917
+ setupState[ref] = value;
5918
+ }
5919
+ }
5920
+ else if (isRef(ref)) {
5921
+ ref.value = value;
5922
+ if (rawRef.k)
5923
+ refs[rawRef.k] = value;
5924
+ }
5925
+ else if ((process.env.NODE_ENV !== 'production')) {
5926
+ warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
5927
+ }
5928
+ };
5929
+ if (value) {
5930
+ doSet.id = -1;
5931
+ queuePostRenderEffect(doSet, parentSuspense);
5932
+ }
5933
+ else {
5934
+ doSet();
5935
+ }
5936
+ }
5937
+ else if ((process.env.NODE_ENV !== 'production')) {
5938
+ warn$1('Invalid template ref type:', ref, `(${typeof ref})`);
5939
+ }
5940
+ }
5941
+ }
5942
+
5848
5943
  let hasMismatch = false;
5849
5944
  const isSVGContainer = (container) => /svg/.test(container.namespaceURI) && container.tagName !== 'foreignObject';
5850
5945
  const isComment = (node) => node.nodeType === 8 /* COMMENT */;
@@ -6233,45 +6328,7 @@ function initFeatureFlags() {
6233
6328
  `which expects these compile-time feature flags to be globally injected ` +
6234
6329
  `via the bundler config in order to get better tree-shaking in the ` +
6235
6330
  `production bundle.\n\n` +
6236
- `For more details, see http://link.vuejs.org/feature-flags.`);
6237
- }
6238
- }
6239
-
6240
- function convertLegacyRefInFor(vnode) {
6241
- // refInFor
6242
- if (vnode.props && vnode.props.refInFor) {
6243
- delete vnode.props.refInFor;
6244
- if (vnode.ref) {
6245
- if (isArray(vnode.ref)) {
6246
- vnode.ref.forEach(r => (r.f = true));
6247
- }
6248
- else {
6249
- vnode.ref.f = true;
6250
- }
6251
- }
6252
- }
6253
- }
6254
- function registerLegacyRef(refs, key, value, owner, isInFor, isUnmount) {
6255
- const existing = refs[key];
6256
- if (isUnmount) {
6257
- if (isArray(existing)) {
6258
- remove(existing, value);
6259
- }
6260
- else {
6261
- refs[key] = null;
6262
- }
6263
- }
6264
- else if (isInFor) {
6265
- (process.env.NODE_ENV !== 'production') && warnDeprecation("V_FOR_REF" /* V_FOR_REF */, owner);
6266
- if (!isArray(existing)) {
6267
- refs[key] = [value];
6268
- }
6269
- else if (!existing.includes(value)) {
6270
- existing.push(value);
6271
- }
6272
- }
6273
- else {
6274
- refs[key] = value;
6331
+ `For more details, see https://link.vuejs.org/feature-flags.`);
6275
6332
  }
6276
6333
  }
6277
6334
 
@@ -6561,12 +6618,15 @@ function baseCreateRenderer(options, createHydrationFns) {
6561
6618
  const oldProps = n1.props || EMPTY_OBJ;
6562
6619
  const newProps = n2.props || EMPTY_OBJ;
6563
6620
  let vnodeHook;
6621
+ // disable recurse in beforeUpdate hooks
6622
+ parentComponent && toggleRecurse(parentComponent, false);
6564
6623
  if ((vnodeHook = newProps.onVnodeBeforeUpdate)) {
6565
6624
  invokeVNodeHook(vnodeHook, parentComponent, n2, n1);
6566
6625
  }
6567
6626
  if (dirs) {
6568
6627
  invokeDirectiveHook(n2, n1, parentComponent, 'beforeUpdate');
6569
6628
  }
6629
+ parentComponent && toggleRecurse(parentComponent, true);
6570
6630
  if ((process.env.NODE_ENV !== 'production') && isHmrUpdating) {
6571
6631
  // HMR updated, force full diff
6572
6632
  patchFlag = 0;
@@ -6850,7 +6910,7 @@ function baseCreateRenderer(options, createHydrationFns) {
6850
6910
  const { el, props } = initialVNode;
6851
6911
  const { bm, m, parent } = instance;
6852
6912
  const isAsyncWrapperVNode = isAsyncWrapper(initialVNode);
6853
- effect.allowRecurse = false;
6913
+ toggleRecurse(instance, false);
6854
6914
  // beforeMount hook
6855
6915
  if (bm) {
6856
6916
  invokeArrayFns(bm);
@@ -6863,7 +6923,7 @@ function baseCreateRenderer(options, createHydrationFns) {
6863
6923
  if (isCompatEnabled("INSTANCE_EVENT_HOOKS" /* INSTANCE_EVENT_HOOKS */, instance)) {
6864
6924
  instance.emit('hook:beforeMount');
6865
6925
  }
6866
- effect.allowRecurse = true;
6926
+ toggleRecurse(instance, true);
6867
6927
  if (el && hydrateNode) {
6868
6928
  // vnode has adopted host node - perform hydration instead of mount.
6869
6929
  const hydrateSubTree = () => {
@@ -6951,7 +7011,7 @@ function baseCreateRenderer(options, createHydrationFns) {
6951
7011
  pushWarningContext(next || instance.vnode);
6952
7012
  }
6953
7013
  // Disallow component effect recursion during pre-lifecycle hooks.
6954
- effect.allowRecurse = false;
7014
+ toggleRecurse(instance, false);
6955
7015
  if (next) {
6956
7016
  next.el = vnode.el;
6957
7017
  updateComponentPreRender(instance, next, optimized);
@@ -6970,7 +7030,7 @@ function baseCreateRenderer(options, createHydrationFns) {
6970
7030
  if (isCompatEnabled("INSTANCE_EVENT_HOOKS" /* INSTANCE_EVENT_HOOKS */, instance)) {
6971
7031
  instance.emit('hook:beforeUpdate');
6972
7032
  }
6973
- effect.allowRecurse = true;
7033
+ toggleRecurse(instance, true);
6974
7034
  // render
6975
7035
  if ((process.env.NODE_ENV !== 'production')) {
6976
7036
  startMeasure(instance, `render`);
@@ -7019,13 +7079,13 @@ function baseCreateRenderer(options, createHydrationFns) {
7019
7079
  }
7020
7080
  };
7021
7081
  // create reactive effect for rendering
7022
- const effect = new ReactiveEffect(componentUpdateFn, () => queueJob(instance.update), instance.scope // track it in component's effect scope
7023
- );
7082
+ const effect = (instance.effect = new ReactiveEffect(componentUpdateFn, () => queueJob(instance.update), instance.scope // track it in component's effect scope
7083
+ ));
7024
7084
  const update = (instance.update = effect.run.bind(effect));
7025
7085
  update.id = instance.uid;
7026
7086
  // allowRecurse
7027
7087
  // #1801, #2043 component render effects should allow recursive updates
7028
- effect.allowRecurse = update.allowRecurse = true;
7088
+ toggleRecurse(instance, true);
7029
7089
  if ((process.env.NODE_ENV !== 'production')) {
7030
7090
  effect.onTrack = instance.rtc
7031
7091
  ? e => invokeArrayFns(instance.rtc, e)
@@ -7555,88 +7615,8 @@ function baseCreateRenderer(options, createHydrationFns) {
7555
7615
  createApp: createAppAPI(render, hydrate)
7556
7616
  };
7557
7617
  }
7558
- function setRef(rawRef, oldRawRef, parentSuspense, vnode, isUnmount = false) {
7559
- if (isArray(rawRef)) {
7560
- rawRef.forEach((r, i) => setRef(r, oldRawRef && (isArray(oldRawRef) ? oldRawRef[i] : oldRawRef), parentSuspense, vnode, isUnmount));
7561
- return;
7562
- }
7563
- if (isAsyncWrapper(vnode) && !isUnmount) {
7564
- // when mounting async components, nothing needs to be done,
7565
- // because the template ref is forwarded to inner component
7566
- return;
7567
- }
7568
- const refValue = vnode.shapeFlag & 4 /* STATEFUL_COMPONENT */
7569
- ? getExposeProxy(vnode.component) || vnode.component.proxy
7570
- : vnode.el;
7571
- const value = isUnmount ? null : refValue;
7572
- const { i: owner, r: ref } = rawRef;
7573
- if ((process.env.NODE_ENV !== 'production') && !owner) {
7574
- warn$1(`Missing ref owner context. ref cannot be used on hoisted vnodes. ` +
7575
- `A vnode with ref must be created inside the render function.`);
7576
- return;
7577
- }
7578
- const oldRef = oldRawRef && oldRawRef.r;
7579
- const refs = owner.refs === EMPTY_OBJ ? (owner.refs = {}) : owner.refs;
7580
- const setupState = owner.setupState;
7581
- // dynamic ref changed. unset old ref
7582
- if (oldRef != null && oldRef !== ref) {
7583
- if (isString(oldRef)) {
7584
- refs[oldRef] = null;
7585
- if (hasOwn(setupState, oldRef)) {
7586
- setupState[oldRef] = null;
7587
- }
7588
- }
7589
- else if (isRef(oldRef)) {
7590
- oldRef.value = null;
7591
- }
7592
- }
7593
- if (isString(ref)) {
7594
- const doSet = () => {
7595
- if (isCompatEnabled("V_FOR_REF" /* V_FOR_REF */, owner)) {
7596
- registerLegacyRef(refs, ref, refValue, owner, rawRef.f, isUnmount);
7597
- }
7598
- else {
7599
- refs[ref] = value;
7600
- }
7601
- if (hasOwn(setupState, ref)) {
7602
- setupState[ref] = value;
7603
- }
7604
- };
7605
- // #1789: for non-null values, set them after render
7606
- // null values means this is unmount and it should not overwrite another
7607
- // ref with the same key
7608
- if (value) {
7609
- doSet.id = -1;
7610
- queuePostRenderEffect(doSet, parentSuspense);
7611
- }
7612
- else {
7613
- doSet();
7614
- }
7615
- }
7616
- else if (isRef(ref)) {
7617
- const doSet = () => {
7618
- ref.value = value;
7619
- };
7620
- if (value) {
7621
- doSet.id = -1;
7622
- queuePostRenderEffect(doSet, parentSuspense);
7623
- }
7624
- else {
7625
- doSet();
7626
- }
7627
- }
7628
- else if (isFunction(ref)) {
7629
- callWithErrorHandling(ref, owner, 12 /* FUNCTION_REF */, [value, refs]);
7630
- }
7631
- else if ((process.env.NODE_ENV !== 'production')) {
7632
- warn$1('Invalid template ref type:', value, `(${typeof value})`);
7633
- }
7634
- }
7635
- function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
7636
- callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
7637
- vnode,
7638
- prevVNode
7639
- ]);
7618
+ function toggleRecurse({ effect, update }, allowed) {
7619
+ effect.allowRecurse = update.allowRecurse = allowed;
7640
7620
  }
7641
7621
  /**
7642
7622
  * #1156
@@ -8436,10 +8416,10 @@ const createVNodeWithArgsTransform = (...args) => {
8436
8416
  };
8437
8417
  const InternalObjectKey = `__vInternal`;
8438
8418
  const normalizeKey = ({ key }) => key != null ? key : null;
8439
- const normalizeRef = ({ ref }) => {
8419
+ const normalizeRef = ({ ref, ref_key, ref_for }) => {
8440
8420
  return (ref != null
8441
8421
  ? isString(ref) || isRef(ref) || isFunction(ref)
8442
- ? { i: currentRenderingInstance, r: ref }
8422
+ ? { i: currentRenderingInstance, r: ref, k: ref_key, f: !!ref_for }
8443
8423
  : ref
8444
8424
  : null);
8445
8425
  };
@@ -8507,7 +8487,6 @@ function createBaseVNode(type, props = null, children = null, patchFlag = 0, dyn
8507
8487
  }
8508
8488
  {
8509
8489
  convertLegacyVModelProps(vnode);
8510
- convertLegacyRefInFor(vnode);
8511
8490
  defineLegacyVNodeProperties(vnode);
8512
8491
  }
8513
8492
  return vnode;
@@ -8793,6 +8772,12 @@ function mergeProps(...args) {
8793
8772
  }
8794
8773
  }
8795
8774
  return ret;
8775
+ }
8776
+ function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
8777
+ callWithAsyncErrorHandling(hook, instance, 7 /* VNODE_HOOK */, [
8778
+ vnode,
8779
+ prevVNode
8780
+ ]);
8796
8781
  }
8797
8782
 
8798
8783
  function getCompatChildren(instance) {
@@ -9456,6 +9441,7 @@ function createComponentInstance(vnode, parent, suspense) {
9456
9441
  root: null,
9457
9442
  next: null,
9458
9443
  subTree: null,
9444
+ effect: null,
9459
9445
  update: null,
9460
9446
  scope: new EffectScope(true /* detached */),
9461
9447
  render: null,
@@ -10975,7 +10961,7 @@ function isMemoSame(cached, memo) {
10975
10961
  }
10976
10962
 
10977
10963
  // Core API ------------------------------------------------------------------
10978
- const version = "3.2.24";
10964
+ const version = "3.2.25";
10979
10965
  const _ssrUtils = {
10980
10966
  createComponentInstance,
10981
10967
  setupComponent,