vue 3.2.19 → 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.
@@ -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 {
@@ -1656,6 +1668,11 @@ function setDevtoolsHook(hook, target) {
1656
1668
  replay.push((newHook) => {
1657
1669
  setDevtoolsHook(newHook, target);
1658
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);
1659
1676
  }
1660
1677
  }
1661
1678
  function devtoolsInitApp(app, version) {
@@ -8674,15 +8691,21 @@ function getContext() {
8674
8691
  * only.
8675
8692
  * @internal
8676
8693
  */
8677
- function mergeDefaults(
8678
- // the base props is compiler-generated and guaranteed to be in this shape.
8679
- props, defaults) {
8694
+ function mergeDefaults(raw, defaults) {
8695
+ const props = isArray(raw)
8696
+ ? raw.reduce((normalized, p) => ((normalized[p] = {}), normalized), {})
8697
+ : raw;
8680
8698
  for (const key in defaults) {
8681
- const val = props[key];
8682
- if (val) {
8683
- 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
+ }
8684
8707
  }
8685
- else if (val === null) {
8708
+ else if (opt === null) {
8686
8709
  props[key] = { default: defaults[key] };
8687
8710
  }
8688
8711
  else {
@@ -8691,6 +8714,23 @@ props, defaults) {
8691
8714
  }
8692
8715
  return props;
8693
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
+ }
8694
8734
  /**
8695
8735
  * `<script setup>` helper for persisting the current instance context over
8696
8736
  * async/await flows.
@@ -8983,7 +9023,7 @@ function isMemoSame(cached, memo) {
8983
9023
  }
8984
9024
 
8985
9025
  // Core API ------------------------------------------------------------------
8986
- const version = "3.2.19";
9026
+ const version = "3.2.20";
8987
9027
  /**
8988
9028
  * SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
8989
9029
  * @internal
@@ -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, 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 };
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 };