vue 3.2.38 → 3.2.40

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.
@@ -1876,7 +1876,9 @@ function queuePostFlushCb(cb) {
1876
1876
  }
1877
1877
  queueFlush();
1878
1878
  }
1879
- function flushPreFlushCbs(seen, i = flushIndex) {
1879
+ function flushPreFlushCbs(seen,
1880
+ // if currently flushing, skip the current job itself
1881
+ i = isFlushing ? flushIndex + 1 : 0) {
1880
1882
  {
1881
1883
  seen = seen || new Map();
1882
1884
  }
@@ -4247,7 +4249,7 @@ function injectHook(type, hook, target = currentInstance, prepend = false) {
4247
4249
  const createHook = (lifecycle) => (hook, target = currentInstance) =>
4248
4250
  // post-create lifecycle registrations are noops during SSR (except for serverPrefetch)
4249
4251
  (!isInSSRComponentSetup || lifecycle === "sp" /* LifecycleHooks.SERVER_PREFETCH */) &&
4250
- injectHook(lifecycle, hook, target);
4252
+ injectHook(lifecycle, (...args) => hook(...args), target);
4251
4253
  const onBeforeMount = createHook("bm" /* LifecycleHooks.BEFORE_MOUNT */);
4252
4254
  const onMounted = createHook("m" /* LifecycleHooks.MOUNTED */);
4253
4255
  const onBeforeUpdate = createHook("bu" /* LifecycleHooks.BEFORE_UPDATE */);
@@ -4470,7 +4472,10 @@ function createSlots(slots, dynamicSlots) {
4470
4472
  slots[slot.name] = slot.key
4471
4473
  ? (...args) => {
4472
4474
  const res = slot.fn(...args);
4473
- res.key = slot.key;
4475
+ // attach branch key so each conditional branch is considered a
4476
+ // different fragment
4477
+ if (res)
4478
+ res.key = slot.key;
4474
4479
  return res;
4475
4480
  }
4476
4481
  : slot.fn;
@@ -6122,7 +6127,7 @@ function createHydrationFunctions(rendererInternals) {
6122
6127
  const isFragmentStart = isComment(node) && node.data === '[';
6123
6128
  const onMismatch = () => handleMismatch(node, vnode, parentComponent, parentSuspense, slotScopeIds, isFragmentStart);
6124
6129
  const { type, ref, shapeFlag, patchFlag } = vnode;
6125
- const domType = node.nodeType;
6130
+ let domType = node.nodeType;
6126
6131
  vnode.el = node;
6127
6132
  if (patchFlag === -2 /* PatchFlags.BAIL */) {
6128
6133
  optimized = false;
@@ -6162,10 +6167,12 @@ function createHydrationFunctions(rendererInternals) {
6162
6167
  }
6163
6168
  break;
6164
6169
  case Static:
6165
- if (domType !== 1 /* DOMNodeTypes.ELEMENT */ && domType !== 3 /* DOMNodeTypes.TEXT */) {
6166
- nextNode = onMismatch();
6170
+ if (isFragmentStart) {
6171
+ // entire template is static but SSRed as a fragment
6172
+ node = nextSibling(node);
6173
+ domType = node.nodeType;
6167
6174
  }
6168
- else {
6175
+ if (domType === 1 /* DOMNodeTypes.ELEMENT */ || domType === 3 /* DOMNodeTypes.TEXT */) {
6169
6176
  // determine anchor, adopt content
6170
6177
  nextNode = node;
6171
6178
  // if the static vnode has its content stripped during build,
@@ -6182,7 +6189,10 @@ function createHydrationFunctions(rendererInternals) {
6182
6189
  }
6183
6190
  nextNode = nextSibling(nextNode);
6184
6191
  }
6185
- return nextNode;
6192
+ return isFragmentStart ? nextSibling(nextNode) : nextNode;
6193
+ }
6194
+ else {
6195
+ onMismatch();
6186
6196
  }
6187
6197
  break;
6188
6198
  case Fragment:
@@ -6507,7 +6517,7 @@ function baseCreateRenderer(options, createHydrationFns) {
6507
6517
  {
6508
6518
  setDevtoolsHook(target.__VUE_DEVTOOLS_GLOBAL_HOOK__, target);
6509
6519
  }
6510
- const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = NOOP, cloneNode: hostCloneNode, insertStaticContent: hostInsertStaticContent } = options;
6520
+ const { insert: hostInsert, remove: hostRemove, patchProp: hostPatchProp, createElement: hostCreateElement, createText: hostCreateText, createComment: hostCreateComment, setText: hostSetText, setElementText: hostSetElementText, parentNode: hostParentNode, nextSibling: hostNextSibling, setScopeId: hostSetScopeId = NOOP, insertStaticContent: hostInsertStaticContent } = options;
6511
6521
  // Note: functions inside this closure should use `const xxx = () => {}`
6512
6522
  // style in order to prevent being inlined by minifiers.
6513
6523
  const patch = (n1, n2, container, anchor = null, parentComponent = null, parentSuspense = null, isSVG = false, slotScopeIds = null, optimized = isHmrUpdating ? false : !!n2.dynamicChildren) => {
@@ -6634,46 +6644,44 @@ function baseCreateRenderer(options, createHydrationFns) {
6634
6644
  const mountElement = (vnode, container, anchor, parentComponent, parentSuspense, isSVG, slotScopeIds, optimized) => {
6635
6645
  let el;
6636
6646
  let vnodeHook;
6637
- const { type, props, shapeFlag, transition, patchFlag, dirs } = vnode;
6638
- {
6639
- el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
6640
- // mount children first, since some props may rely on child content
6641
- // being already rendered, e.g. `<select value>`
6642
- if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
6643
- hostSetElementText(el, vnode.children);
6644
- }
6645
- else if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
6646
- mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
6647
- }
6648
- if (dirs) {
6649
- invokeDirectiveHook(vnode, null, parentComponent, 'created');
6650
- }
6651
- // props
6652
- if (props) {
6653
- for (const key in props) {
6654
- if (key !== 'value' && !isReservedProp(key)) {
6655
- hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
6656
- }
6657
- }
6658
- /**
6659
- * Special case for setting value on DOM elements:
6660
- * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
6661
- * - it needs to be forced (#1471)
6662
- * #2353 proposes adding another renderer option to configure this, but
6663
- * the properties affects are so finite it is worth special casing it
6664
- * here to reduce the complexity. (Special casing it also should not
6665
- * affect non-DOM renderers)
6666
- */
6667
- if ('value' in props) {
6668
- hostPatchProp(el, 'value', null, props.value);
6669
- }
6670
- if ((vnodeHook = props.onVnodeBeforeMount)) {
6671
- invokeVNodeHook(vnodeHook, parentComponent, vnode);
6672
- }
6673
- }
6674
- // scopeId
6675
- setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
6647
+ const { type, props, shapeFlag, transition, dirs } = vnode;
6648
+ el = vnode.el = hostCreateElement(vnode.type, isSVG, props && props.is, props);
6649
+ // mount children first, since some props may rely on child content
6650
+ // being already rendered, e.g. `<select value>`
6651
+ if (shapeFlag & 8 /* ShapeFlags.TEXT_CHILDREN */) {
6652
+ hostSetElementText(el, vnode.children);
6653
+ }
6654
+ else if (shapeFlag & 16 /* ShapeFlags.ARRAY_CHILDREN */) {
6655
+ mountChildren(vnode.children, el, null, parentComponent, parentSuspense, isSVG && type !== 'foreignObject', slotScopeIds, optimized);
6676
6656
  }
6657
+ if (dirs) {
6658
+ invokeDirectiveHook(vnode, null, parentComponent, 'created');
6659
+ }
6660
+ // props
6661
+ if (props) {
6662
+ for (const key in props) {
6663
+ if (key !== 'value' && !isReservedProp(key)) {
6664
+ hostPatchProp(el, key, null, props[key], isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
6665
+ }
6666
+ }
6667
+ /**
6668
+ * Special case for setting value on DOM elements:
6669
+ * - it can be order-sensitive (e.g. should be set *after* min/max, #2325, #4024)
6670
+ * - it needs to be forced (#1471)
6671
+ * #2353 proposes adding another renderer option to configure this, but
6672
+ * the properties affects are so finite it is worth special casing it
6673
+ * here to reduce the complexity. (Special casing it also should not
6674
+ * affect non-DOM renderers)
6675
+ */
6676
+ if ('value' in props) {
6677
+ hostPatchProp(el, 'value', null, props.value);
6678
+ }
6679
+ if ((vnodeHook = props.onVnodeBeforeMount)) {
6680
+ invokeVNodeHook(vnodeHook, parentComponent, vnode);
6681
+ }
6682
+ }
6683
+ // scopeId
6684
+ setScopeId(el, vnode, vnode.scopeId, slotScopeIds, parentComponent);
6677
6685
  {
6678
6686
  Object.defineProperty(el, '__vnode', {
6679
6687
  value: vnode,
@@ -6859,6 +6867,13 @@ function baseCreateRenderer(options, createHydrationFns) {
6859
6867
  };
6860
6868
  const patchProps = (el, vnode, oldProps, newProps, parentComponent, parentSuspense, isSVG) => {
6861
6869
  if (oldProps !== newProps) {
6870
+ if (oldProps !== EMPTY_OBJ) {
6871
+ for (const key in oldProps) {
6872
+ if (!isReservedProp(key) && !(key in newProps)) {
6873
+ hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
6874
+ }
6875
+ }
6876
+ }
6862
6877
  for (const key in newProps) {
6863
6878
  // empty string is not valid prop
6864
6879
  if (isReservedProp(key))
@@ -6870,13 +6885,6 @@ function baseCreateRenderer(options, createHydrationFns) {
6870
6885
  hostPatchProp(el, key, prev, next, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
6871
6886
  }
6872
6887
  }
6873
- if (oldProps !== EMPTY_OBJ) {
6874
- for (const key in oldProps) {
6875
- if (!isReservedProp(key) && !(key in newProps)) {
6876
- hostPatchProp(el, key, oldProps[key], null, isSVG, vnode.children, parentComponent, parentSuspense, unmountChildren);
6877
- }
6878
- }
6879
- }
6880
6888
  if ('value' in newProps) {
6881
6889
  hostPatchProp(el, 'value', oldProps.value, newProps.value);
6882
6890
  }
@@ -8400,7 +8408,10 @@ function normalizeVNode(child) {
8400
8408
  }
8401
8409
  // optimized normalization for template-compiled render fns
8402
8410
  function cloneIfMounted(child) {
8403
- return child.el === null || child.memo ? child : cloneVNode(child);
8411
+ return (child.el === null && child.patchFlag !== -1 /* PatchFlags.HOISTED */) ||
8412
+ child.memo
8413
+ ? child
8414
+ : cloneVNode(child);
8404
8415
  }
8405
8416
  function normalizeChildren(vnode, children) {
8406
8417
  let type = 0;
@@ -8742,7 +8753,8 @@ function finishComponentSetup(instance, isSSR, skipOptions) {
8742
8753
  // only do on-the-fly compile if not in SSR - SSR on-the-fly compilation
8743
8754
  // is done by server-renderer
8744
8755
  if (!isSSR && compile && !Component.render) {
8745
- const template = Component.template;
8756
+ const template = Component.template ||
8757
+ resolveMergedOptions(instance).template;
8746
8758
  if (template) {
8747
8759
  {
8748
8760
  startMeasure(instance, `compile`);
@@ -9297,7 +9309,7 @@ function isMemoSame(cached, memo) {
9297
9309
  }
9298
9310
 
9299
9311
  // Core API ------------------------------------------------------------------
9300
- const version = "3.2.38";
9312
+ const version = "3.2.40";
9301
9313
  /**
9302
9314
  * SSR utils for \@vue/server-renderer. Only exposed in ssr-possible builds.
9303
9315
  * @internal
@@ -9348,22 +9360,6 @@ const nodeOps = {
9348
9360
  setScopeId(el, id) {
9349
9361
  el.setAttribute(id, '');
9350
9362
  },
9351
- cloneNode(el) {
9352
- const cloned = el.cloneNode(true);
9353
- // #3072
9354
- // - in `patchDOMProp`, we store the actual value in the `el._value` property.
9355
- // - normally, elements using `:value` bindings will not be hoisted, but if
9356
- // the bound value is a constant, e.g. `:value="true"` - they do get
9357
- // hoisted.
9358
- // - in production, hoisted nodes are cloned when subsequent inserts, but
9359
- // cloneNode() does not copy the custom property we attached.
9360
- // - This may need to account for other custom DOM properties we attach to
9361
- // elements in addition to `_value` in the future.
9362
- if (`_value` in el) {
9363
- cloned._value = el._value;
9364
- }
9365
- return cloned;
9366
- },
9367
9363
  // __UNSAFE__
9368
9364
  // Reason: innerHTML.
9369
9365
  // Static content here can only come from compiled templates.
@@ -9575,7 +9571,6 @@ prevChildren, parentComponent, parentSuspense, unmountChildren) {
9575
9571
  }
9576
9572
  else if (type === 'number') {
9577
9573
  // e.g. <img :width="null">
9578
- // the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error
9579
9574
  value = 0;
9580
9575
  needRemove = true;
9581
9576
  }
@@ -9587,7 +9582,8 @@ prevChildren, parentComponent, parentSuspense, unmountChildren) {
9587
9582
  el[key] = value;
9588
9583
  }
9589
9584
  catch (e) {
9590
- {
9585
+ // do not warn if value is auto-coerced from nullish values
9586
+ if (!needRemove) {
9591
9587
  warn$1(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
9592
9588
  `value ${value} is invalid.`, e);
9593
9589
  }
@@ -11957,34 +11953,42 @@ function parseChildren(context, mode, ancestors) {
11957
11953
  const shouldCondense = context.options.whitespace !== 'preserve';
11958
11954
  for (let i = 0; i < nodes.length; i++) {
11959
11955
  const node = nodes[i];
11960
- if (!context.inPre && node.type === 2 /* NodeTypes.TEXT */) {
11961
- if (!/[^\t\r\n\f ]/.test(node.content)) {
11962
- const prev = nodes[i - 1];
11963
- const next = nodes[i + 1];
11964
- // Remove if:
11965
- // - the whitespace is the first or last node, or:
11966
- // - (condense mode) the whitespace is adjacent to a comment, or:
11967
- // - (condense mode) the whitespace is between two elements AND contains newline
11968
- if (!prev ||
11969
- !next ||
11970
- (shouldCondense &&
11971
- (prev.type === 3 /* NodeTypes.COMMENT */ ||
11972
- next.type === 3 /* NodeTypes.COMMENT */ ||
11973
- (prev.type === 1 /* NodeTypes.ELEMENT */ &&
11974
- next.type === 1 /* NodeTypes.ELEMENT */ &&
11975
- /[\r\n]/.test(node.content))))) {
11976
- removedWhitespace = true;
11977
- nodes[i] = null;
11956
+ if (node.type === 2 /* NodeTypes.TEXT */) {
11957
+ if (!context.inPre) {
11958
+ if (!/[^\t\r\n\f ]/.test(node.content)) {
11959
+ const prev = nodes[i - 1];
11960
+ const next = nodes[i + 1];
11961
+ // Remove if:
11962
+ // - the whitespace is the first or last node, or:
11963
+ // - (condense mode) the whitespace is adjacent to a comment, or:
11964
+ // - (condense mode) the whitespace is between two elements AND contains newline
11965
+ if (!prev ||
11966
+ !next ||
11967
+ (shouldCondense &&
11968
+ (prev.type === 3 /* NodeTypes.COMMENT */ ||
11969
+ next.type === 3 /* NodeTypes.COMMENT */ ||
11970
+ (prev.type === 1 /* NodeTypes.ELEMENT */ &&
11971
+ next.type === 1 /* NodeTypes.ELEMENT */ &&
11972
+ /[\r\n]/.test(node.content))))) {
11973
+ removedWhitespace = true;
11974
+ nodes[i] = null;
11975
+ }
11976
+ else {
11977
+ // Otherwise, the whitespace is condensed into a single space
11978
+ node.content = ' ';
11979
+ }
11978
11980
  }
11979
- else {
11980
- // Otherwise, the whitespace is condensed into a single space
11981
- node.content = ' ';
11981
+ else if (shouldCondense) {
11982
+ // in condense mode, consecutive whitespaces in text are condensed
11983
+ // down to a single space.
11984
+ node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ');
11982
11985
  }
11983
11986
  }
11984
- else if (shouldCondense) {
11985
- // in condense mode, consecutive whitespaces in text are condensed
11986
- // down to a single space.
11987
- node.content = node.content.replace(/[\t\r\n\f ]+/g, ' ');
11987
+ else {
11988
+ // #6410 normalize windows newlines in <pre>:
11989
+ // in SSR, browsers normalize server-rendered \r\n into a single \n
11990
+ // in the DOM
11991
+ node.content = node.content.replace(/\r\n/g, '\n');
11988
11992
  }
11989
11993
  }
11990
11994
  // Remove comment nodes if desired by configuration.
@@ -12625,11 +12629,6 @@ function walk(node, context, doNotHoistNode = false) {
12625
12629
  }
12626
12630
  }
12627
12631
  }
12628
- else if (child.type === 12 /* NodeTypes.TEXT_CALL */ &&
12629
- getConstantType(child.content, context) >= 2 /* ConstantTypes.CAN_HOIST */) {
12630
- child.codegenNode = context.hoist(child.codegenNode);
12631
- hoistedCount++;
12632
- }
12633
12632
  // walk further
12634
12633
  if (child.type === 1 /* NodeTypes.ELEMENT */) {
12635
12634
  const isComponent = child.tagType === 1 /* ElementTypes.COMPONENT */;
@@ -14640,6 +14639,14 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
14640
14639
  let hasDynamicKeys = false;
14641
14640
  let hasVnodeHook = false;
14642
14641
  const dynamicPropNames = [];
14642
+ const pushMergeArg = (arg) => {
14643
+ if (properties.length) {
14644
+ mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
14645
+ properties = [];
14646
+ }
14647
+ if (arg)
14648
+ mergeArgs.push(arg);
14649
+ };
14643
14650
  const analyzePatchFlag = ({ key, value }) => {
14644
14651
  if (isStaticExp(key)) {
14645
14652
  const name = key.content;
@@ -14752,16 +14759,14 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
14752
14759
  if (!arg && (isVBind || isVOn)) {
14753
14760
  hasDynamicKeys = true;
14754
14761
  if (exp) {
14755
- if (properties.length) {
14756
- mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
14757
- properties = [];
14758
- }
14759
14762
  if (isVBind) {
14763
+ // have to merge early for compat build check
14764
+ pushMergeArg();
14760
14765
  mergeArgs.push(exp);
14761
14766
  }
14762
14767
  else {
14763
14768
  // v-on="obj" -> toHandlers(obj)
14764
- mergeArgs.push({
14769
+ pushMergeArg({
14765
14770
  type: 14 /* NodeTypes.JS_CALL_EXPRESSION */,
14766
14771
  loc,
14767
14772
  callee: context.helper(TO_HANDLERS),
@@ -14781,7 +14786,12 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
14781
14786
  // has built-in directive transform.
14782
14787
  const { props, needRuntime } = directiveTransform(prop, node, context);
14783
14788
  !ssr && props.forEach(analyzePatchFlag);
14784
- properties.push(...props);
14789
+ if (isVOn && arg && !isStaticExp(arg)) {
14790
+ pushMergeArg(createObjectExpression(props, elementLoc));
14791
+ }
14792
+ else {
14793
+ properties.push(...props);
14794
+ }
14785
14795
  if (needRuntime) {
14786
14796
  runtimeDirectives.push(prop);
14787
14797
  if (isSymbol(needRuntime)) {
@@ -14803,9 +14813,8 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
14803
14813
  let propsExpression = undefined;
14804
14814
  // has v-bind="object" or v-on="object", wrap with mergeProps
14805
14815
  if (mergeArgs.length) {
14806
- if (properties.length) {
14807
- mergeArgs.push(createObjectExpression(dedupeProperties(properties), elementLoc));
14808
- }
14816
+ // close up any not-yet-merged props
14817
+ pushMergeArg();
14809
14818
  if (mergeArgs.length > 1) {
14810
14819
  propsExpression = createCallExpression(context.helper(MERGE_PROPS), mergeArgs, elementLoc);
14811
14820
  }