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