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.
@@ -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,11 +1647,12 @@ 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
  }
@@ -1650,12 +1663,32 @@ function setDevtoolsHook(hook, target) {
1650
1663
  buffer.forEach(({ event, args }) => devtools.emit(event, ...args));
1651
1664
  buffer = [];
1652
1665
  }
1653
- else {
1666
+ else if (
1667
+ // handle late devtools injection - only do this if we are in an actual
1668
+ // browser environment to avoid the timer handle stalling test runner exit
1669
+ // (#4815)
1670
+ // eslint-disable-next-line no-restricted-globals
1671
+ typeof window !== 'undefined' &&
1672
+ !navigator.userAgent.includes('jsdom')) {
1654
1673
  const replay = (target.__VUE_DEVTOOLS_HOOK_REPLAY__ =
1655
1674
  target.__VUE_DEVTOOLS_HOOK_REPLAY__ || []);
1656
1675
  replay.push((newHook) => {
1657
1676
  setDevtoolsHook(newHook, target);
1658
1677
  });
1678
+ // clear buffer after 3s - the user probably doesn't have devtools installed
1679
+ // at all, and keeping the buffer will cause memory leaks (#4738)
1680
+ setTimeout(() => {
1681
+ if (!devtools) {
1682
+ target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
1683
+ devtoolsNotInstalled = true;
1684
+ buffer = [];
1685
+ }
1686
+ }, 3000);
1687
+ }
1688
+ else {
1689
+ // non-browser env, assume not installed
1690
+ devtoolsNotInstalled = true;
1691
+ buffer = [];
1659
1692
  }
1660
1693
  }
1661
1694
  function devtoolsInitApp(app, version) {
@@ -4444,7 +4477,7 @@ return withDirectives(h(comp), [
4444
4477
  [bar, this.y]
4445
4478
  ])
4446
4479
  */
4447
- const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text');
4480
+ const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
4448
4481
  function validateDirectiveName(name) {
4449
4482
  if (isBuiltInDirective(name)) {
4450
4483
  warn$1('Do not use built-in directive ids as custom directive id: ' + name);
@@ -8674,15 +8707,21 @@ function getContext() {
8674
8707
  * only.
8675
8708
  * @internal
8676
8709
  */
8677
- function mergeDefaults(
8678
- // the base props is compiler-generated and guaranteed to be in this shape.
8679
- props, defaults) {
8710
+ function mergeDefaults(raw, defaults) {
8711
+ const props = isArray(raw)
8712
+ ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
8713
+ : raw;
8680
8714
  for (const key in defaults) {
8681
- const val = props[key];
8682
- if (val) {
8683
- val.default = defaults[key];
8715
+ const opt = props[key];
8716
+ if (opt) {
8717
+ if (isArray(opt) || isFunction(opt)) {
8718
+ props[key] = { type: opt, default: defaults[key] };
8719
+ }
8720
+ else {
8721
+ opt.default = defaults[key];
8722
+ }
8684
8723
  }
8685
- else if (val === null) {
8724
+ else if (opt === null) {
8686
8725
  props[key] = { default: defaults[key] };
8687
8726
  }
8688
8727
  else {
@@ -8691,6 +8730,23 @@ props, defaults) {
8691
8730
  }
8692
8731
  return props;
8693
8732
  }
8733
+ /**
8734
+ * Used to create a proxy for the rest element when destructuring props with
8735
+ * defineProps().
8736
+ * @internal
8737
+ */
8738
+ function createPropsRestProxy(props, excludedKeys) {
8739
+ const ret = {};
8740
+ for (const key in props) {
8741
+ if (!excludedKeys.includes(key)) {
8742
+ Object.defineProperty(ret, key, {
8743
+ enumerable: true,
8744
+ get: () => props[key]
8745
+ });
8746
+ }
8747
+ }
8748
+ return ret;
8749
+ }
8694
8750
  /**
8695
8751
  * `<script setup>` helper for persisting the current instance context over
8696
8752
  * async/await flows.
@@ -8983,7 +9039,7 @@ function isMemoSame(cached, memo) {
8983
9039
  }
8984
9040
 
8985
9041
  // Core API ------------------------------------------------------------------
8986
- const version = "3.2.17";
9042
+ const version = "3.2.21";
8987
9043
  /**
8988
9044
  * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
8989
9045
  * @internal
@@ -9105,16 +9161,8 @@ function patchClass(el, value, isSVG) {
9105
9161
 
9106
9162
  function patchStyle(el, prev, next) {
9107
9163
  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 {
9164
+ const isCssString = isString(next);
9165
+ if (next && !isCssString) {
9118
9166
  for (const key in next) {
9119
9167
  setStyle(style, key, next[key]);
9120
9168
  }
@@ -9126,11 +9174,22 @@ function patchStyle(el, prev, next) {
9126
9174
  }
9127
9175
  }
9128
9176
  }
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;
9177
+ else {
9178
+ const currentDisplay = style.display;
9179
+ if (isCssString) {
9180
+ if (prev !== next) {
9181
+ style.cssText = next;
9182
+ }
9183
+ }
9184
+ else if (prev) {
9185
+ el.removeAttribute('style');
9186
+ }
9187
+ // indicates that the `display` of the element is controlled by `v-show`,
9188
+ // so we always keep the current `display` value regardless of the `style`
9189
+ // value, thus handing over control to `v-show`.
9190
+ if ('_vod' in el) {
9191
+ style.display = currentDisplay;
9192
+ }
9134
9193
  }
9135
9194
  }
9136
9195
  const importantRE = /\s*!important$/;
@@ -9476,22 +9535,11 @@ class VueElement extends BaseClass {
9476
9535
  }
9477
9536
  this.attachShadow({ mode: 'open' });
9478
9537
  }
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
9538
  }
9490
9539
  connectedCallback() {
9491
9540
  this._connected = true;
9492
9541
  if (!this._instance) {
9493
9542
  this._resolveDef();
9494
- this._update();
9495
9543
  }
9496
9544
  }
9497
9545
  disconnectedCallback() {
@@ -9510,8 +9558,18 @@ class VueElement extends BaseClass {
9510
9558
  if (this._resolved) {
9511
9559
  return;
9512
9560
  }
9561
+ this._resolved = true;
9562
+ // set initial attrs
9563
+ for (let i = 0; i < this.attributes.length; i++) {
9564
+ this._setAttr(this.attributes[i].name);
9565
+ }
9566
+ // watch future attr changes
9567
+ new MutationObserver(mutations => {
9568
+ for (const m of mutations) {
9569
+ this._setAttr(m.attributeName);
9570
+ }
9571
+ }).observe(this, { attributes: true });
9513
9572
  const resolve = (def) => {
9514
- this._resolved = true;
9515
9573
  const { props, styles } = def;
9516
9574
  const hasOptions = !isArray(props);
9517
9575
  const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
@@ -9526,14 +9584,11 @@ class VueElement extends BaseClass {
9526
9584
  }
9527
9585
  }
9528
9586
  }
9529
- if (numberProps) {
9530
- this._numberProps = numberProps;
9531
- this._update();
9532
- }
9587
+ this._numberProps = numberProps;
9533
9588
  // check if there are props set pre-upgrade or connect
9534
9589
  for (const key of Object.keys(this)) {
9535
9590
  if (key[0] !== '_') {
9536
- this._setProp(key, this[key]);
9591
+ this._setProp(key, this[key], true, false);
9537
9592
  }
9538
9593
  }
9539
9594
  // defining getter/setters on prototype
@@ -9547,7 +9602,10 @@ class VueElement extends BaseClass {
9547
9602
  }
9548
9603
  });
9549
9604
  }
9605
+ // apply CSS
9550
9606
  this._applyStyles(styles);
9607
+ // initial render
9608
+ this._update();
9551
9609
  };
9552
9610
  const asyncDef = this._def.__asyncLoader;
9553
9611
  if (asyncDef) {
@@ -9573,10 +9631,10 @@ class VueElement extends BaseClass {
9573
9631
  /**
9574
9632
  * @internal
9575
9633
  */
9576
- _setProp(key, val, shouldReflect = true) {
9634
+ _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
9577
9635
  if (val !== this._props[key]) {
9578
9636
  this._props[key] = val;
9579
- if (this._instance) {
9637
+ if (shouldUpdate && this._instance) {
9580
9638
  this._update();
9581
9639
  }
9582
9640
  // reflect
@@ -10687,6 +10745,7 @@ var runtimeDom = /*#__PURE__*/Object.freeze({
10687
10745
  defineExpose: defineExpose,
10688
10746
  withDefaults: withDefaults,
10689
10747
  mergeDefaults: mergeDefaults,
10748
+ createPropsRestProxy: createPropsRestProxy,
10690
10749
  withAsyncContext: withAsyncContext,
10691
10750
  getCurrentInstance: getCurrentInstance,
10692
10751
  h: h,
@@ -11167,7 +11226,7 @@ const isMemberExpressionBrowser = (path) => {
11167
11226
  const isMemberExpression = isMemberExpressionBrowser
11168
11227
  ;
11169
11228
  function getInnerRange(loc, offset, length) {
11170
- const source = loc.source.substr(offset, length);
11229
+ const source = loc.source.slice(offset, offset + length);
11171
11230
  const newLoc = {
11172
11231
  source,
11173
11232
  start: advancePositionWithClone(loc.start, loc.source, offset),
@@ -11994,10 +12053,10 @@ function parseAttribute(context, nameSet) {
11994
12053
  isStatic = false;
11995
12054
  if (!content.endsWith(']')) {
11996
12055
  emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
11997
- content = content.substr(1);
12056
+ content = content.slice(1);
11998
12057
  }
11999
12058
  else {
12000
- content = content.substr(1, content.length - 2);
12059
+ content = content.slice(1, content.length - 1);
12001
12060
  }
12002
12061
  }
12003
12062
  else if (isSlot) {
@@ -12023,7 +12082,7 @@ function parseAttribute(context, nameSet) {
12023
12082
  valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
12024
12083
  valueLoc.source = valueLoc.source.slice(1, -1);
12025
12084
  }
12026
- const modifiers = match[3] ? match[3].substr(1).split('.') : [];
12085
+ const modifiers = match[3] ? match[3].slice(1).split('.') : [];
12027
12086
  if (isPropShorthand)
12028
12087
  modifiers.push('prop');
12029
12088
  return {
@@ -12233,7 +12292,7 @@ function isEnd(context, mode, ancestors) {
12233
12292
  }
12234
12293
  function startsWithEndTagOpen(source, tag) {
12235
12294
  return (startsWith(source, '</') &&
12236
- source.substr(2, tag.length).toLowerCase() === tag.toLowerCase() &&
12295
+ source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() &&
12237
12296
  /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
12238
12297
  }
12239
12298
 
@@ -15603,4 +15662,4 @@ function compileToFunction(template, options) {
15603
15662
  }
15604
15663
  registerRuntimeCompiler(compileToFunction);
15605
15664
 
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 };
15665
+ 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 };