vue 3.2.16 → 3.2.20

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.
@@ -1513,14 +1513,7 @@ const hmrDirtyComponents = new Set();
1513
1513
  // Note: for a component to be eligible for HMR it also needs the __hmrId option
1514
1514
  // to be set so that its instances can be registered / removed.
1515
1515
  {
1516
- const globalObject = typeof global !== 'undefined'
1517
- ? global
1518
- : typeof self !== 'undefined'
1519
- ? self
1520
- : typeof window !== 'undefined'
1521
- ? window
1522
- : {};
1523
- globalObject.__VUE_HMR_RUNTIME__ = {
1516
+ getGlobalThis().__VUE_HMR_RUNTIME__ = {
1524
1517
  createRecord: tryWrap(createRecord),
1525
1518
  rerender: tryWrap(rerender),
1526
1519
  reload: tryWrap(reload)
@@ -1531,19 +1524,22 @@ function registerHMR(instance) {
1531
1524
  const id = instance.type.__hmrId;
1532
1525
  let record = map.get(id);
1533
1526
  if (!record) {
1534
- createRecord(id);
1527
+ createRecord(id, instance.type);
1535
1528
  record = map.get(id);
1536
1529
  }
1537
- record.add(instance);
1530
+ record.instances.add(instance);
1538
1531
  }
1539
1532
  function unregisterHMR(instance) {
1540
- map.get(instance.type.__hmrId).delete(instance);
1533
+ map.get(instance.type.__hmrId).instances.delete(instance);
1541
1534
  }
1542
- function createRecord(id) {
1535
+ function createRecord(id, initialDef) {
1543
1536
  if (map.has(id)) {
1544
1537
  return false;
1545
1538
  }
1546
- map.set(id, new Set());
1539
+ map.set(id, {
1540
+ initialDef: normalizeClassComponent(initialDef),
1541
+ instances: new Set()
1542
+ });
1547
1543
  return true;
1548
1544
  }
1549
1545
  function normalizeClassComponent(component) {
@@ -1554,7 +1550,9 @@ function rerender(id, newRender) {
1554
1550
  if (!record) {
1555
1551
  return;
1556
1552
  }
1557
- [...record].forEach(instance => {
1553
+ // update initial record (for not-yet-rendered component)
1554
+ record.initialDef.render = newRender;
1555
+ [...record.instances].forEach(instance => {
1558
1556
  if (newRender) {
1559
1557
  instance.render = newRender;
1560
1558
  normalizeClassComponent(instance.type).render = newRender;
@@ -1571,17 +1569,16 @@ function reload(id, newComp) {
1571
1569
  if (!record)
1572
1570
  return;
1573
1571
  newComp = normalizeClassComponent(newComp);
1572
+ // update initial def (for not-yet-rendered components)
1573
+ updateComponentDef(record.initialDef, newComp);
1574
1574
  // create a snapshot which avoids the set being mutated during updates
1575
- const instances = [...record];
1575
+ const instances = [...record.instances];
1576
1576
  for (const instance of instances) {
1577
1577
  const oldComp = normalizeClassComponent(instance.type);
1578
1578
  if (!hmrDirtyComponents.has(oldComp)) {
1579
1579
  // 1. Update existing comp definition to match new one
1580
- extend(oldComp, newComp);
1581
- for (const key in oldComp) {
1582
- if (key !== '__file' && !(key in newComp)) {
1583
- delete oldComp[key];
1584
- }
1580
+ if (oldComp !== record.initialDef) {
1581
+ updateComponentDef(oldComp, newComp);
1585
1582
  }
1586
1583
  // 2. mark definition dirty. This forces the renderer to replace the
1587
1584
  // component on patch.
@@ -1627,6 +1624,14 @@ function reload(id, newComp) {
1627
1624
  }
1628
1625
  });
1629
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
+ }
1630
1635
  function tryWrap(fn) {
1631
1636
  return (id, arg) => {
1632
1637
  try {
@@ -1663,6 +1668,11 @@ function setDevtoolsHook(hook, target) {
1663
1668
  replay.push((newHook) => {
1664
1669
  setDevtoolsHook(newHook, target);
1665
1670
  });
1671
+ // clear buffer after 3s - the user probably doesn't have devtools installed
1672
+ // at all, and keeping the buffer will cause memory leaks (#4738)
1673
+ setTimeout(() => {
1674
+ buffer = [];
1675
+ }, 3000);
1666
1676
  }
1667
1677
  }
1668
1678
  function devtoolsInitApp(app, version) {
@@ -7787,9 +7797,11 @@ const isRuntimeOnly = () => !compile;
7787
7797
  function finishComponentSetup(instance, isSSR, skipOptions) {
7788
7798
  const Component = instance.type;
7789
7799
  // template / render function normalization
7800
+ // could be already set when returned from setup()
7790
7801
  if (!instance.render) {
7791
- // could be set from setup()
7792
- if (compile && !Component.render) {
7802
+ // only do on-the-fly compile if not in SSR - SSR on-the-fly compliation
7803
+ // is done by server-renderer
7804
+ if (!isSSR && compile && !Component.render) {
7793
7805
  const template = Component.template;
7794
7806
  if (template) {
7795
7807
  {
@@ -8679,15 +8691,21 @@ function getContext() {
8679
8691
  * only.
8680
8692
  * @internal
8681
8693
  */
8682
- function mergeDefaults(
8683
- // the base props is compiler-generated and guaranteed to be in this shape.
8684
- props, defaults) {
8694
+ function mergeDefaults(raw, defaults) {
8695
+ const props = isArray(raw)
8696
+ ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
8697
+ : raw;
8685
8698
  for (const key in defaults) {
8686
- const val = props[key];
8687
- if (val) {
8688
- val.default = defaults[key];
8699
+ const opt = props[key];
8700
+ if (opt) {
8701
+ if (isArray(opt) || isFunction(opt)) {
8702
+ props[key] = { type: opt, default: defaults[key] };
8703
+ }
8704
+ else {
8705
+ opt.default = defaults[key];
8706
+ }
8689
8707
  }
8690
- else if (val === null) {
8708
+ else if (opt === null) {
8691
8709
  props[key] = { default: defaults[key] };
8692
8710
  }
8693
8711
  else {
@@ -8696,6 +8714,23 @@ props, defaults) {
8696
8714
  }
8697
8715
  return props;
8698
8716
  }
8717
+ /**
8718
+ * Used to create a proxy for the rest element when destructuring props with
8719
+ * defineProps().
8720
+ * @internal
8721
+ */
8722
+ function createPropsRestProxy(props, excludedKeys) {
8723
+ const ret = {};
8724
+ for (const key in props) {
8725
+ if (!excludedKeys.includes(key)) {
8726
+ Object.defineProperty(ret, key, {
8727
+ enumerable: true,
8728
+ get: () => props[key]
8729
+ });
8730
+ }
8731
+ }
8732
+ return ret;
8733
+ }
8699
8734
  /**
8700
8735
  * `<script setup>` helper for persisting the current instance context over
8701
8736
  * async/await flows.
@@ -8988,7 +9023,7 @@ function isMemoSame(cached, memo) {
8988
9023
  }
8989
9024
 
8990
9025
  // Core API ------------------------------------------------------------------
8991
- const version = "3.2.16";
9026
+ const version = "3.2.20";
8992
9027
  /**
8993
9028
  * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
8994
9029
  * @internal
@@ -10610,7 +10645,11 @@ function normalizeContainer(container) {
10610
10645
  warn$1(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
10611
10646
  }
10612
10647
  return container;
10613
- }
10648
+ }
10649
+ /**
10650
+ * @internal
10651
+ */
10652
+ const initDirectivesForSSR = NOOP;
10614
10653
 
10615
10654
  var runtimeDom = /*#__PURE__*/Object.freeze({
10616
10655
  __proto__: null,
@@ -10618,6 +10657,7 @@ var runtimeDom = /*#__PURE__*/Object.freeze({
10618
10657
  hydrate: hydrate,
10619
10658
  createApp: createApp,
10620
10659
  createSSRApp: createSSRApp,
10660
+ initDirectivesForSSR: initDirectivesForSSR,
10621
10661
  defineCustomElement: defineCustomElement,
10622
10662
  defineSSRCustomElement: defineSSRCustomElement,
10623
10663
  VueElement: VueElement,
@@ -10687,6 +10727,7 @@ var runtimeDom = /*#__PURE__*/Object.freeze({
10687
10727
  defineExpose: defineExpose,
10688
10728
  withDefaults: withDefaults,
10689
10729
  mergeDefaults: mergeDefaults,
10730
+ createPropsRestProxy: createPropsRestProxy,
10690
10731
  withAsyncContext: withAsyncContext,
10691
10732
  getCurrentInstance: getCurrentInstance,
10692
10733
  h: h,
@@ -11167,7 +11208,7 @@ const isMemberExpressionBrowser = (path) => {
11167
11208
  const isMemberExpression = isMemberExpressionBrowser
11168
11209
  ;
11169
11210
  function getInnerRange(loc, offset, length) {
11170
- const source = loc.source.substr(offset, length);
11211
+ const source = loc.source.slice(offset, offset + length);
11171
11212
  const newLoc = {
11172
11213
  source,
11173
11214
  start: advancePositionWithClone(loc.start, loc.source, offset),
@@ -11994,10 +12035,10 @@ function parseAttribute(context, nameSet) {
11994
12035
  isStatic = false;
11995
12036
  if (!content.endsWith(']')) {
11996
12037
  emitError(context, 27 /* X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */);
11997
- content = content.substr(1);
12038
+ content = content.slice(1);
11998
12039
  }
11999
12040
  else {
12000
- content = content.substr(1, content.length - 2);
12041
+ content = content.slice(1, content.length - 1);
12001
12042
  }
12002
12043
  }
12003
12044
  else if (isSlot) {
@@ -12023,7 +12064,7 @@ function parseAttribute(context, nameSet) {
12023
12064
  valueLoc.end = advancePositionWithClone(valueLoc.start, value.content);
12024
12065
  valueLoc.source = valueLoc.source.slice(1, -1);
12025
12066
  }
12026
- const modifiers = match[3] ? match[3].substr(1).split('.') : [];
12067
+ const modifiers = match[3] ? match[3].slice(1).split('.') : [];
12027
12068
  if (isPropShorthand)
12028
12069
  modifiers.push('prop');
12029
12070
  return {
@@ -12233,7 +12274,7 @@ function isEnd(context, mode, ancestors) {
12233
12274
  }
12234
12275
  function startsWithEndTagOpen(source, tag) {
12235
12276
  return (startsWith(source, '</') &&
12236
- source.substr(2, tag.length).toLowerCase() === tag.toLowerCase() &&
12277
+ source.slice(2, 2 + tag.length).toLowerCase() === tag.toLowerCase() &&
12237
12278
  /[\t\r\n\f />]/.test(source[2 + tag.length] || '>'));
12238
12279
  }
12239
12280
 
@@ -15603,4 +15644,4 @@ function compileToFunction(template, options) {
15603
15644
  }
15604
15645
  registerRuntimeCompiler(compileToFunction);
15605
15646
 
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, 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 };
15647
+ 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 };