vue 3.2.17 → 3.2.21

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.
@@ -1527,19 +1527,22 @@ var Vue = (function (exports) {
1527
1527
  const id = instance.type.__hmrId;
1528
1528
  let record = map.get(id);
1529
1529
  if (!record) {
1530
- createRecord(id);
1530
+ createRecord(id, instance.type);
1531
1531
  record = map.get(id);
1532
1532
  }
1533
- record.add(instance);
1533
+ record.instances.add(instance);
1534
1534
  }
1535
1535
  function unregisterHMR(instance) {
1536
- map.get(instance.type.__hmrId).delete(instance);
1536
+ map.get(instance.type.__hmrId).instances.delete(instance);
1537
1537
  }
1538
- function createRecord(id) {
1538
+ function createRecord(id, initialDef) {
1539
1539
  if (map.has(id)) {
1540
1540
  return false;
1541
1541
  }
1542
- map.set(id, new Set());
1542
+ map.set(id, {
1543
+ initialDef: normalizeClassComponent(initialDef),
1544
+ instances: new Set()
1545
+ });
1543
1546
  return true;
1544
1547
  }
1545
1548
  function normalizeClassComponent(component) {
@@ -1550,7 +1553,9 @@ var Vue = (function (exports) {
1550
1553
  if (!record) {
1551
1554
  return;
1552
1555
  }
1553
- [...record].forEach(instance => {
1556
+ // update initial record (for not-yet-rendered component)
1557
+ record.initialDef.render = newRender;
1558
+ [...record.instances].forEach(instance => {
1554
1559
  if (newRender) {
1555
1560
  instance.render = newRender;
1556
1561
  normalizeClassComponent(instance.type).render = newRender;
@@ -1567,17 +1572,16 @@ var Vue = (function (exports) {
1567
1572
  if (!record)
1568
1573
  return;
1569
1574
  newComp = normalizeClassComponent(newComp);
1575
+ // update initial def (for not-yet-rendered components)
1576
+ updateComponentDef(record.initialDef, newComp);
1570
1577
  // create a snapshot which avoids the set being mutated during updates
1571
- const instances = [...record];
1578
+ const instances = [...record.instances];
1572
1579
  for (const instance of instances) {
1573
1580
  const oldComp = normalizeClassComponent(instance.type);
1574
1581
  if (!hmrDirtyComponents.has(oldComp)) {
1575
1582
  // 1. Update existing comp definition to match new one
1576
- extend(oldComp, newComp);
1577
- for (const key in oldComp) {
1578
- if (key !== '__file' && !(key in newComp)) {
1579
- delete oldComp[key];
1580
- }
1583
+ if (oldComp !== record.initialDef) {
1584
+ updateComponentDef(oldComp, newComp);
1581
1585
  }
1582
1586
  // 2. mark definition dirty. This forces the renderer to replace the
1583
1587
  // component on patch.
@@ -1623,6 +1627,14 @@ var Vue = (function (exports) {
1623
1627
  }
1624
1628
  });
1625
1629
  }
1630
+ function updateComponentDef(oldComp, newComp) {
1631
+ extend(oldComp, newComp);
1632
+ for (const key in oldComp) {
1633
+ if (key !== '__file' && !(key in newComp)) {
1634
+ delete oldComp[key];
1635
+ }
1636
+ }
1637
+ }
1626
1638
  function tryWrap(fn) {
1627
1639
  return (id, arg) => {
1628
1640
  try {
@@ -1637,11 +1649,12 @@ var Vue = (function (exports) {
1637
1649
  }
1638
1650
 
1639
1651
  let buffer = [];
1652
+ let devtoolsNotInstalled = false;
1640
1653
  function emit(event, ...args) {
1641
1654
  if (exports.devtools) {
1642
1655
  exports.devtools.emit(event, ...args);
1643
1656
  }
1644
- else {
1657
+ else if (!devtoolsNotInstalled) {
1645
1658
  buffer.push({ event, args });
1646
1659
  }
1647
1660
  }
@@ -1652,12 +1665,32 @@ var Vue = (function (exports) {
1652
1665
  buffer.forEach(({ event, args }) => exports.devtools.emit(event, ...args));
1653
1666
  buffer = [];
1654
1667
  }
1655
- else {
1668
+ else if (
1669
+ // handle late devtools injection - only do this if we are in an actual
1670
+ // browser environment to avoid the timer handle stalling test runner exit
1671
+ // (#4815)
1672
+ // eslint-disable-next-line no-restricted-globals
1673
+ typeof window !== 'undefined' &&
1674
+ !navigator.userAgent.includes('jsdom')) {
1656
1675
  const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
1657
1676
  target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
1658
1677
  replay.push((newHook) => {
1659
1678
  setDevtoolsHook(newHook, target);
1660
1679
  });
1680
+ // clear buffer after 3s - the user probably doesn't have devtools installed
1681
+ // at all, and keeping the buffer will cause memory leaks (#4738)
1682
+ setTimeout(() => {
1683
+ if (!exports.devtools) {
1684
+ target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
1685
+ devtoolsNotInstalled = true;
1686
+ buffer = [];
1687
+ }
1688
+ }, 3000);
1689
+ }
1690
+ else {
1691
+ // non-browser env, assume not installed
1692
+ devtoolsNotInstalled = true;
1693
+ buffer = [];
1661
1694
  }
1662
1695
  }
1663
1696
  function devtoolsInitApp(app, version) {
@@ -4446,7 +4479,7 @@ var Vue = (function (exports) {
4446
4479
  [bar, this.y]
4447
4480
  ])
4448
4481
  */
4449
- const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text');
4482
+ const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
4450
4483
  function validateDirectiveName(name) {
4451
4484
  if (isBuiltInDirective(name)) {
4452
4485
  warn$1('Do not use built-in directive ids as custom directive id: ' + name);
@@ -8676,15 +8709,21 @@ var Vue = (function (exports) {
8676
8709
  * only.
8677
8710
  * @internal
8678
8711
  */
8679
- function mergeDefaults(
8680
- // the base props is compiler-generated and guaranteed to be in this shape.
8681
- props, defaults) {
8712
+ function mergeDefaults(raw, defaults) {
8713
+ const props = isArray(raw)
8714
+ ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
8715
+ : raw;
8682
8716
  for (const key in defaults) {
8683
- const val = props[key];
8684
- if (val) {
8685
- val.default = defaults[key];
8717
+ const opt = props[key];
8718
+ if (opt) {
8719
+ if (isArray(opt) || isFunction(opt)) {
8720
+ props[key] = { type: opt, default: defaults[key] };
8721
+ }
8722
+ else {
8723
+ opt.default = defaults[key];
8724
+ }
8686
8725
  }
8687
- else if (val === null) {
8726
+ else if (opt === null) {
8688
8727
  props[key] = { default: defaults[key] };
8689
8728
  }
8690
8729
  else {
@@ -8693,6 +8732,23 @@ var Vue = (function (exports) {
8693
8732
  }
8694
8733
  return props;
8695
8734
  }
8735
+ /**
8736
+ * Used to create a proxy for the rest element when destructuring props with
8737
+ * defineProps().
8738
+ * @internal
8739
+ */
8740
+ function createPropsRestProxy(props, excludedKeys) {
8741
+ const ret = {};
8742
+ for (const key in props) {
8743
+ if (!excludedKeys.includes(key)) {
8744
+ Object.defineProperty(ret, key, {
8745
+ enumerable: true,
8746
+ get: () => props[key]
8747
+ });
8748
+ }
8749
+ }
8750
+ return ret;
8751
+ }
8696
8752
  /**
8697
8753
  * `<script setup>` helper for persisting the current instance context over
8698
8754
  * async/await flows.
@@ -8980,7 +9036,7 @@ var Vue = (function (exports) {
8980
9036
  }
8981
9037
 
8982
9038
  // Core API ------------------------------------------------------------------
8983
- const version = "3.2.17";
9039
+ const version = "3.2.21";
8984
9040
  /**
8985
9041
  * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
8986
9042
  * @internal
@@ -9102,16 +9158,8 @@ var Vue = (function (exports) {
9102
9158
 
9103
9159
  function patchStyle(el, prev, next) {
9104
9160
  const style = el.style;
9105
- const currentDisplay = style.display;
9106
- if (!next) {
9107
- el.removeAttribute('style');
9108
- }
9109
- else if (isString(next)) {
9110
- if (prev !== next) {
9111
- style.cssText = next;
9112
- }
9113
- }
9114
- else {
9161
+ const isCssString = isString(next);
9162
+ if (next && !isCssString) {
9115
9163
  for (const key in next) {
9116
9164
  setStyle(style, key, next[key]);
9117
9165
  }
@@ -9123,11 +9171,22 @@ var Vue = (function (exports) {
9123
9171
  }
9124
9172
  }
9125
9173
  }
9126
- // indicates that the `display` of the element is controlled by `v-show`,
9127
- // so we always keep the current `display` value regardless of the `style` value,
9128
- // thus handing over control to `v-show`.
9129
- if ('_vod' in el) {
9130
- style.display = currentDisplay;
9174
+ else {
9175
+ const currentDisplay = style.display;
9176
+ if (isCssString) {
9177
+ if (prev !== next) {
9178
+ style.cssText = next;
9179
+ }
9180
+ }
9181
+ else if (prev) {
9182
+ el.removeAttribute('style');
9183
+ }
9184
+ // indicates that the `display` of the element is controlled by `v-show`,
9185
+ // so we always keep the current `display` value regardless of the `style`
9186
+ // value, thus handing over control to `v-show`.
9187
+ if ('_vod' in el) {
9188
+ style.display = currentDisplay;
9189
+ }
9131
9190
  }
9132
9191
  }
9133
9192
  const importantRE = /\s*!important$/;
@@ -9473,22 +9532,11 @@ var Vue = (function (exports) {
9473
9532
  }
9474
9533
  this.attachShadow({ mode: 'open' });
9475
9534
  }
9476
- // set initial attrs
9477
- for (let i = 0; i < this.attributes.length; i++) {
9478
- this._setAttr(this.attributes[i].name);
9479
- }
9480
- // watch future attr changes
9481
- new MutationObserver(mutations => {
9482
- for (const m of mutations) {
9483
- this._setAttr(m.attributeName);
9484
- }
9485
- }).observe(this, { attributes: true });
9486
9535
  }
9487
9536
  connectedCallback() {
9488
9537
  this._connected = true;
9489
9538
  if (!this._instance) {
9490
9539
  this._resolveDef();
9491
- this._update();
9492
9540
  }
9493
9541
  }
9494
9542
  disconnectedCallback() {
@@ -9507,8 +9555,18 @@ var Vue = (function (exports) {
9507
9555
  if (this._resolved) {
9508
9556
  return;
9509
9557
  }
9558
+ this._resolved = true;
9559
+ // set initial attrs
9560
+ for (let i = 0; i < this.attributes.length; i++) {
9561
+ this._setAttr(this.attributes[i].name);
9562
+ }
9563
+ // watch future attr changes
9564
+ new MutationObserver(mutations => {
9565
+ for (const m of mutations) {
9566
+ this._setAttr(m.attributeName);
9567
+ }
9568
+ }).observe(this, { attributes: true });
9510
9569
  const resolve = (def) => {
9511
- this._resolved = true;
9512
9570
  const { props, styles } = def;
9513
9571
  const hasOptions = !isArray(props);
9514
9572
  const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
@@ -9523,14 +9581,11 @@ var Vue = (function (exports) {
9523
9581
  }
9524
9582
  }
9525
9583
  }
9526
- if (numberProps) {
9527
- this._numberProps = numberProps;
9528
- this._update();
9529
- }
9584
+ this._numberProps = numberProps;
9530
9585
  // check if there are props set pre-upgrade or connect
9531
9586
  for (const key of Object.keys(this)) {
9532
9587
  if (key[0] !== '_') {
9533
- this._setProp(key, this[key]);
9588
+ this._setProp(key, this[key], true, false);
9534
9589
  }
9535
9590
  }
9536
9591
  // defining getter/setters on prototype
@@ -9544,7 +9599,10 @@ var Vue = (function (exports) {
9544
9599
  }
9545
9600
  });
9546
9601
  }
9602
+ // apply CSS
9547
9603
  this._applyStyles(styles);
9604
+ // initial render
9605
+ this._update();
9548
9606
  };
9549
9607
  const asyncDef = this._def.__asyncLoader;
9550
9608
  if (asyncDef) {
@@ -9570,10 +9628,10 @@ var Vue = (function (exports) {
9570
9628
  /**
9571
9629
  * @internal
9572
9630
  */
9573
- _setProp(key, val, shouldReflect = true) {
9631
+ _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
9574
9632
  if (val !== this._props[key]) {
9575
9633
  this._props[key] = val;
9576
- if (this._instance) {
9634
+ if (shouldUpdate && this._instance) {
9577
9635
  this._update();
9578
9636
  }
9579
9637
  // reflect
@@ -11006,7 +11064,7 @@ var Vue = (function (exports) {
11006
11064
  const isMemberExpression = isMemberExpressionBrowser
11007
11065
  ;
11008
11066
  function getInnerRange(loc, offset, length) {
11009
- const source = loc.source.substr(offset, length);
11067
+ const source = loc.source.slice(offset, offset + length);
11010
11068
  const newLoc = {
11011
11069
  source,
11012
11070
  start: advancePositionWithClone(loc.start, loc.source, offset),
@@ -11833,10 +11891,10 @@ var Vue = (function (exports) {
11833
11891
  isStatic = false;
11834
11892
  if (!content.endsWith(']')) {
11835
11893
  emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
11836
- content = content.substr(1);
11894
+ content = content.slice(1);
11837
11895
  }
11838
11896
  else {
11839
- content = content.substr(1, content.length - 2);
11897
+ content = content.slice(1, content.length - 1);
11840
11898
  }
11841
11899
  }
11842
11900
  else if (isSlot) {
@@ -11862,7 +11920,7 @@ var Vue = (function (exports) {
11862
11920
  valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
11863
11921
  valueLoc.source = valueLoc.source.slice(1, -1);
11864
11922
  }
11865
- const modifiers = match[3] ? match[3].substr(1).split('.') : [];
11923
+ const modifiers = match[3] ? match[3].slice(1).split('.') : [];
11866
11924
  if (isPropShorthand)
11867
11925
  modifiers.push('prop');
11868
11926
  return {
@@ -12072,7 +12130,7 @@ var Vue = (function (exports) {
12072
12130
  }
12073
12131
  function startsWithEndTagOpen(source, tag) {
12074
12132
  return (startsWith(source, '</') &&
12075
- source.substr(2, tag.length).toLowerCase() === tag.toLowerCase() &&
12133
+ source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() &&
12076
12134
  /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
12077
12135
  }
12078
12136
 
@@ -15469,6 +15527,7 @@ var Vue = (function (exports) {
15469
15527
  exports.createElementBlock = createElementBlock;
15470
15528
  exports.createElementVNode = createBaseVNode;
15471
15529
  exports.createHydrationRenderer = createHydrationRenderer;
15530
+ exports.createPropsRestProxy = createPropsRestProxy;
15472
15531
  exports.createRenderer = createRenderer;
15473
15532
  exports.createSSRApp = createSSRApp;
15474
15533
  exports.createSlots = createSlots;