vue 3.2.18 → 3.2.22

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.
@@ -1524,19 +1524,22 @@ function registerHMR(instance) {
1524
1524
  const id = instance.type.__hmrId;
1525
1525
  let record = map.get(id);
1526
1526
  if (!record) {
1527
- createRecord(id);
1527
+ createRecord(id, instance.type);
1528
1528
  record = map.get(id);
1529
1529
  }
1530
- record.add(instance);
1530
+ record.instances.add(instance);
1531
1531
  }
1532
1532
  function unregisterHMR(instance) {
1533
- map.get(instance.type.__hmrId).delete(instance);
1533
+ map.get(instance.type.__hmrId).instances.delete(instance);
1534
1534
  }
1535
- function createRecord(id) {
1535
+ function createRecord(id, initialDef) {
1536
1536
  if (map.has(id)) {
1537
1537
  return false;
1538
1538
  }
1539
- map.set(id, new Set());
1539
+ map.set(id, {
1540
+ initialDef: normalizeClassComponent(initialDef),
1541
+ instances: new Set()
1542
+ });
1540
1543
  return true;
1541
1544
  }
1542
1545
  function normalizeClassComponent(component) {
@@ -1547,7 +1550,9 @@ function rerender(id, newRender) {
1547
1550
  if (!record) {
1548
1551
  return;
1549
1552
  }
1550
- [...record].forEach(instance => {
1553
+ // update initial record (for not-yet-rendered component)
1554
+ record.initialDef.render = newRender;
1555
+ [...record.instances].forEach(instance => {
1551
1556
  if (newRender) {
1552
1557
  instance.render = newRender;
1553
1558
  normalizeClassComponent(instance.type).render = newRender;
@@ -1564,17 +1569,16 @@ function reload(id, newComp) {
1564
1569
  if (!record)
1565
1570
  return;
1566
1571
  newComp = normalizeClassComponent(newComp);
1572
+ // update initial def (for not-yet-rendered components)
1573
+ updateComponentDef(record.initialDef, newComp);
1567
1574
  // create a snapshot which avoids the set being mutated during updates
1568
- const instances = [...record];
1575
+ const instances = [...record.instances];
1569
1576
  for (const instance of instances) {
1570
1577
  const oldComp = normalizeClassComponent(instance.type);
1571
1578
  if (!hmrDirtyComponents.has(oldComp)) {
1572
1579
  // 1. Update existing comp definition to match new one
1573
- extend(oldComp, newComp);
1574
- for (const key in oldComp) {
1575
- if (key !== '__file' && !(key in newComp)) {
1576
- delete oldComp[key];
1577
- }
1580
+ if (oldComp !== record.initialDef) {
1581
+ updateComponentDef(oldComp, newComp);
1578
1582
  }
1579
1583
  // 2. mark definition dirty. This forces the renderer to replace the
1580
1584
  // component on patch.
@@ -1620,6 +1624,14 @@ function reload(id, newComp) {
1620
1624
  }
1621
1625
  });
1622
1626
  }
1627
+ function updateComponentDef(oldComp, newComp) {
1628
+ extend(oldComp, newComp);
1629
+ for (const key in oldComp) {
1630
+ if (key !== '__file' && !(key in newComp)) {
1631
+ delete oldComp[key];
1632
+ }
1633
+ }
1634
+ }
1623
1635
  function tryWrap(fn) {
1624
1636
  return (id, arg) => {
1625
1637
  try {
@@ -1635,27 +1647,52 @@ function tryWrap(fn) {
1635
1647
 
1636
1648
  let devtools;
1637
1649
  let buffer = [];
1650
+ let devtoolsNotInstalled = false;
1638
1651
  function emit(event, ...args) {
1639
1652
  if (devtools) {
1640
1653
  devtools.emit(event, ...args);
1641
1654
  }
1642
- else {
1655
+ else if (!devtoolsNotInstalled) {
1643
1656
  buffer.push({ event, args });
1644
1657
  }
1645
1658
  }
1646
1659
  function setDevtoolsHook(hook, target) {
1660
+ var _a, _b;
1647
1661
  devtools = hook;
1648
1662
  if (devtools) {
1649
1663
  devtools.enabled = true;
1650
1664
  buffer.forEach(({ event, args }) => devtools.emit(event, ...args));
1651
1665
  buffer = [];
1652
1666
  }
1653
- else {
1667
+ else if (
1668
+ // handle late devtools injection - only do this if we are in an actual
1669
+ // browser environment to avoid the timer handle stalling test runner exit
1670
+ // (#4815)
1671
+ // eslint-disable-next-line no-restricted-globals
1672
+ typeof window !== 'undefined' &&
1673
+ // some envs mock window but not fully
1674
+ window.HTMLElement &&
1675
+ // also exclude jsdom
1676
+ !((_b = (_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) === null || _b === void 0 ? void 0 : _b.includes('jsdom'))) {
1654
1677
  const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
1655
1678
  target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
1656
1679
  replay.push((newHook) => {
1657
1680
  setDevtoolsHook(newHook, target);
1658
1681
  });
1682
+ // clear buffer after 3s - the user probably doesn't have devtools installed
1683
+ // at all, and keeping the buffer will cause memory leaks (#4738)
1684
+ setTimeout(() => {
1685
+ if (!devtools) {
1686
+ target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
1687
+ devtoolsNotInstalled = true;
1688
+ buffer = [];
1689
+ }
1690
+ }, 3000);
1691
+ }
1692
+ else {
1693
+ // non-browser env, assume not installed
1694
+ devtoolsNotInstalled = true;
1695
+ buffer = [];
1659
1696
  }
1660
1697
  }
1661
1698
  function devtoolsInitApp(app, version) {
@@ -4444,7 +4481,7 @@ return withDirectives(h(comp), [
4444
4481
  [bar, this.y]
4445
4482
  ])
4446
4483
  */
4447
- const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text');
4484
+ const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
4448
4485
  function validateDirectiveName(name) {
4449
4486
  if (isBuiltInDirective(name)) {
4450
4487
  warn$1('Do not use built-in directive ids as custom directive id: ' + name);
@@ -6361,8 +6398,8 @@ function invokeVNodeHook(hook, instance, vnode, prevVNode = null) {
6361
6398
  *
6362
6399
  * #2080
6363
6400
  * Inside keyed `template` fragment static children, if a fragment is moved,
6364
- * the children will always moved so that need inherit el form previous nodes
6365
- * to ensure correct moved position.
6401
+ * the children will always be moved. Therefore, in order to ensure correct move
6402
+ * position, el should be inherited from previous nodes.
6366
6403
  */
6367
6404
  function traverseStaticChildren(n1, n2, shallow = false) {
6368
6405
  const ch1 = n1.children;
@@ -7142,7 +7179,8 @@ function mergeProps(...args) {
7142
7179
  else if (isOn(key)) {
7143
7180
  const existing = ret[key];
7144
7181
  const incoming = toMerge[key];
7145
- if (existing !== incoming) {
7182
+ if (existing !== incoming &&
7183
+ !(isArray(existing) && existing.includes(incoming))) {
7146
7184
  ret[key] = existing
7147
7185
  ? [].concat(existing, incoming)
7148
7186
  : incoming;
@@ -8674,15 +8712,21 @@ function getContext() {
8674
8712
  * only.
8675
8713
  * @internal
8676
8714
  */
8677
- function mergeDefaults(
8678
- // the base props is compiler-generated and guaranteed to be in this shape.
8679
- props, defaults) {
8715
+ function mergeDefaults(raw, defaults) {
8716
+ const props = isArray(raw)
8717
+ ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
8718
+ : raw;
8680
8719
  for (const key in defaults) {
8681
- const val = props[key];
8682
- if (val) {
8683
- val.default = defaults[key];
8720
+ const opt = props[key];
8721
+ if (opt) {
8722
+ if (isArray(opt) || isFunction(opt)) {
8723
+ props[key] = { type: opt, default: defaults[key] };
8724
+ }
8725
+ else {
8726
+ opt.default = defaults[key];
8727
+ }
8684
8728
  }
8685
- else if (val === null) {
8729
+ else if (opt === null) {
8686
8730
  props[key] = { default: defaults[key] };
8687
8731
  }
8688
8732
  else {
@@ -8691,6 +8735,23 @@ props, defaults) {
8691
8735
  }
8692
8736
  return props;
8693
8737
  }
8738
+ /**
8739
+ * Used to create a proxy for the rest element when destructuring props with
8740
+ * defineProps().
8741
+ * @internal
8742
+ */
8743
+ function createPropsRestProxy(props, excludedKeys) {
8744
+ const ret = {};
8745
+ for (const key in props) {
8746
+ if (!excludedKeys.includes(key)) {
8747
+ Object.defineProperty(ret, key, {
8748
+ enumerable: true,
8749
+ get: () => props[key]
8750
+ });
8751
+ }
8752
+ }
8753
+ return ret;
8754
+ }
8694
8755
  /**
8695
8756
  * `<script setup>` helper for persisting the current instance context over
8696
8757
  * async/await flows.
@@ -8983,7 +9044,7 @@ function isMemoSame(cached, memo) {
8983
9044
  }
8984
9045
 
8985
9046
  // Core API ------------------------------------------------------------------
8986
- const version = "3.2.18";
9047
+ const version = "3.2.22";
8987
9048
  /**
8988
9049
  * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
8989
9050
  * @internal
@@ -9105,16 +9166,8 @@ function patchClass(el, value, isSVG) {
9105
9166
 
9106
9167
  function patchStyle(el, prev, next) {
9107
9168
  const style = el.style;
9108
- const currentDisplay = style.display;
9109
- if (!next) {
9110
- el.removeAttribute('style');
9111
- }
9112
- else if (isString(next)) {
9113
- if (prev !== next) {
9114
- style.cssText = next;
9115
- }
9116
- }
9117
- else {
9169
+ const isCssString = isString(next);
9170
+ if (next && !isCssString) {
9118
9171
  for (const key in next) {
9119
9172
  setStyle(style, key, next[key]);
9120
9173
  }
@@ -9126,11 +9179,22 @@ function patchStyle(el, prev, next) {
9126
9179
  }
9127
9180
  }
9128
9181
  }
9129
- // indicates that the `display` of the element is controlled by `v-show`,
9130
- // so we always keep the current `display` value regardless of the `style` value,
9131
- // thus handing over control to `v-show`.
9132
- if ('_vod' in el) {
9133
- style.display = currentDisplay;
9182
+ else {
9183
+ const currentDisplay = style.display;
9184
+ if (isCssString) {
9185
+ if (prev !== next) {
9186
+ style.cssText = next;
9187
+ }
9188
+ }
9189
+ else if (prev) {
9190
+ el.removeAttribute('style');
9191
+ }
9192
+ // indicates that the `display` of the element is controlled by `v-show`,
9193
+ // so we always keep the current `display` value regardless of the `style`
9194
+ // value, thus handing over control to `v-show`.
9195
+ if ('_vod' in el) {
9196
+ style.display = currentDisplay;
9197
+ }
9134
9198
  }
9135
9199
  }
9136
9200
  const importantRE = /\s*!important$/;
@@ -9476,22 +9540,11 @@ class VueElement extends BaseClass {
9476
9540
  }
9477
9541
  this.attachShadow({ mode: 'open' });
9478
9542
  }
9479
- // set initial attrs
9480
- for (let i = 0; i < this.attributes.length; i++) {
9481
- this._setAttr(this.attributes[i].name);
9482
- }
9483
- // watch future attr changes
9484
- new MutationObserver(mutations => {
9485
- for (const m of mutations) {
9486
- this._setAttr(m.attributeName);
9487
- }
9488
- }).observe(this, { attributes: true });
9489
9543
  }
9490
9544
  connectedCallback() {
9491
9545
  this._connected = true;
9492
9546
  if (!this._instance) {
9493
9547
  this._resolveDef();
9494
- this._update();
9495
9548
  }
9496
9549
  }
9497
9550
  disconnectedCallback() {
@@ -9510,8 +9563,18 @@ class VueElement extends BaseClass {
9510
9563
  if (this._resolved) {
9511
9564
  return;
9512
9565
  }
9566
+ this._resolved = true;
9567
+ // set initial attrs
9568
+ for (let i = 0; i < this.attributes.length; i++) {
9569
+ this._setAttr(this.attributes[i].name);
9570
+ }
9571
+ // watch future attr changes
9572
+ new MutationObserver(mutations => {
9573
+ for (const m of mutations) {
9574
+ this._setAttr(m.attributeName);
9575
+ }
9576
+ }).observe(this, { attributes: true });
9513
9577
  const resolve = (def) => {
9514
- this._resolved = true;
9515
9578
  const { props, styles } = def;
9516
9579
  const hasOptions = !isArray(props);
9517
9580
  const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
@@ -9526,14 +9589,11 @@ class VueElement extends BaseClass {
9526
9589
  }
9527
9590
  }
9528
9591
  }
9529
- if (numberProps) {
9530
- this._numberProps = numberProps;
9531
- this._update();
9532
- }
9592
+ this._numberProps = numberProps;
9533
9593
  // check if there are props set pre-upgrade or connect
9534
9594
  for (const key of Object.keys(this)) {
9535
9595
  if (key[0] !== '_') {
9536
- this._setProp(key, this[key]);
9596
+ this._setProp(key, this[key], true, false);
9537
9597
  }
9538
9598
  }
9539
9599
  // defining getter/setters on prototype
@@ -9547,7 +9607,10 @@ class VueElement extends BaseClass {
9547
9607
  }
9548
9608
  });
9549
9609
  }
9610
+ // apply CSS
9550
9611
  this._applyStyles(styles);
9612
+ // initial render
9613
+ this._update();
9551
9614
  };
9552
9615
  const asyncDef = this._def.__asyncLoader;
9553
9616
  if (asyncDef) {
@@ -9573,10 +9636,10 @@ class VueElement extends BaseClass {
9573
9636
  /**
9574
9637
  * @internal
9575
9638
  */
9576
- _setProp(key, val, shouldReflect = true) {
9639
+ _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
9577
9640
  if (val !== this._props[key]) {
9578
9641
  this._props[key] = val;
9579
- if (this._instance) {
9642
+ if (shouldUpdate && this._instance) {
9580
9643
  this._update();
9581
9644
  }
9582
9645
  // reflect
@@ -10687,6 +10750,7 @@ var runtimeDom = /*#__PURE__*/Object.freeze({
10687
10750
  defineExpose: defineExpose,
10688
10751
  withDefaults: withDefaults,
10689
10752
  mergeDefaults: mergeDefaults,
10753
+ createPropsRestProxy: createPropsRestProxy,
10690
10754
  withAsyncContext: withAsyncContext,
10691
10755
  getCurrentInstance: getCurrentInstance,
10692
10756
  h: h,
@@ -11167,7 +11231,7 @@ const isMemberExpressionBrowser = (path) => {
11167
11231
  const isMemberExpression = isMemberExpressionBrowser
11168
11232
  ;
11169
11233
  function getInnerRange(loc, offset, length) {
11170
- const source = loc.source.substr(offset, length);
11234
+ const source = loc.source.slice(offset, offset + length);
11171
11235
  const newLoc = {
11172
11236
  source,
11173
11237
  start: advancePositionWithClone(loc.start, loc.source, offset),
@@ -11994,10 +12058,10 @@ function parseAttribute(context, nameSet) {
11994
12058
  isStatic = false;
11995
12059
  if (!content.endsWith(']')) {
11996
12060
  emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
11997
- content = content.substr(1);
12061
+ content = content.slice(1);
11998
12062
  }
11999
12063
  else {
12000
- content = content.substr(1, content.length - 2);
12064
+ content = content.slice(1, content.length - 1);
12001
12065
  }
12002
12066
  }
12003
12067
  else if (isSlot) {
@@ -12023,7 +12087,7 @@ function parseAttribute(context, nameSet) {
12023
12087
  valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
12024
12088
  valueLoc.source = valueLoc.source.slice(1, -1);
12025
12089
  }
12026
- const modifiers = match[3] ? match[3].substr(1).split('.') : [];
12090
+ const modifiers = match[3] ? match[3].slice(1).split('.') : [];
12027
12091
  if (isPropShorthand)
12028
12092
  modifiers.push('prop');
12029
12093
  return {
@@ -12233,7 +12297,7 @@ function isEnd(context, mode, ancestors) {
12233
12297
  }
12234
12298
  function startsWithEndTagOpen(source, tag) {
12235
12299
  return (startsWith(source, '</') &&
12236
- source.substr(2, tag.length).toLowerCase() === tag.toLowerCase() &&
12300
+ source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() &&
12237
12301
  /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
12238
12302
  }
12239
12303
 
@@ -14639,7 +14703,7 @@ function stringifyDynamicPropNames(props) {
14639
14703
  return propsNamesString + `]`;
14640
14704
  }
14641
14705
  function isComponentTag(tag) {
14642
- return tag[0].toLowerCase() + tag.slice(1) === 'component';
14706
+ return tag === 'component' || tag === 'Component';
14643
14707
  }
14644
14708
 
14645
14709
  const transformSlotOutlet = (node, context) => {
@@ -15603,4 +15667,4 @@ function compileToFunction(template, options) {
15603
15667
  }
15604
15668
  registerRuntimeCompiler(compileToFunction);
15605
15669
 
15606
- export { BaseTransition, Comment, EffectScope, Fragment, KeepAlive, ReactiveEffect, Static, Suspense, Teleport, Text, Transition, TransitionGroup, VueElement, callWithAsyncErrorHandling, callWithErrorHandling, camelize, capitalize, cloneVNode, compatUtils, compileToFunction as compile, computed, createApp, createBlock, createCommentVNode, createElementBlock, createBaseVNode as createElementVNode, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, customRef, defineAsyncComponent, defineComponent, defineCustomElement, defineEmits, defineExpose, defineProps, defineSSRCustomElement, devtools, effect, effectScope, getCurrentInstance, getCurrentScope, getTransitionRawChildren, guardReactiveProps, h, handleError, hydrate, initCustomFormatter, initDirectivesForSSR, inject, isMemoSame, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeDefaults, mergeProps, nextTick, normalizeClass, normalizeProps, normalizeStyle, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveFilter, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, stop, toDisplayString, toHandlerKey, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useAttrs, useCssModule, useCssVars, useSSRContext, useSlots, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withKeys, withMemo, withModifiers, withScopeId };
15670
+ export { BaseTransition, Comment, EffectScope, Fragment, KeepAlive, ReactiveEffect, Static, Suspense, Teleport, Text, Transition, TransitionGroup, VueElement, callWithAsyncErrorHandling, callWithErrorHandling, camelize, capitalize, cloneVNode, compatUtils, compileToFunction as compile, computed, createApp, createBlock, createCommentVNode, createElementBlock, createBaseVNode as createElementVNode, createHydrationRenderer, createPropsRestProxy, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, customRef, defineAsyncComponent, defineComponent, defineCustomElement, defineEmits, defineExpose, defineProps, defineSSRCustomElement, devtools, effect, effectScope, getCurrentInstance, getCurrentScope, getTransitionRawChildren, guardReactiveProps, h, handleError, hydrate, initCustomFormatter, initDirectivesForSSR, inject, isMemoSame, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeDefaults, mergeProps, nextTick, normalizeClass, normalizeProps, normalizeStyle, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onServerPrefetch, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveFilter, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, stop, toDisplayString, toHandlerKey, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useAttrs, useCssModule, useCssVars, useSSRContext, useSlots, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withKeys, withMemo, withModifiers, withScopeId };