@vue/runtime-core 3.3.0-alpha.9 → 3.3.0-beta.1

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.
@@ -810,7 +810,8 @@ function patchSuspense(n1, n2, container, anchor, parentComponent, isSVG, slotSc
810
810
  }
811
811
  }
812
812
  }
813
- function createSuspenseBoundary(vnode, parent, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
813
+ function createSuspenseBoundary(vnode, parentSuspense, parentComponent, container, hiddenContainer, anchor, isSVG, slotScopeIds, optimized, rendererInternals, isHydrating = false) {
814
+ var _a;
814
815
  const {
815
816
  p: patch,
816
817
  m: move,
@@ -818,10 +819,18 @@ function createSuspenseBoundary(vnode, parent, parentComponent, container, hidde
818
819
  n: next,
819
820
  o: { parentNode, remove }
820
821
  } = rendererInternals;
822
+ let parentSuspenseId;
823
+ const isSuspensible = ((_a = vnode.props) == null ? void 0 : _a.suspensible) != null && vnode.props.suspensible !== false;
824
+ if (isSuspensible) {
825
+ if (parentSuspense == null ? void 0 : parentSuspense.pendingBranch) {
826
+ parentSuspenseId = parentSuspense == null ? void 0 : parentSuspense.pendingId;
827
+ parentSuspense.deps++;
828
+ }
829
+ }
821
830
  const timeout = vnode.props ? shared.toNumber(vnode.props.timeout) : void 0;
822
831
  const suspense = {
823
832
  vnode,
824
- parent,
833
+ parent: parentSuspense,
825
834
  parentComponent,
826
835
  isSVG,
827
836
  container,
@@ -869,20 +878,28 @@ function createSuspenseBoundary(vnode, parent, parentComponent, container, hidde
869
878
  setActiveBranch(suspense, pendingBranch);
870
879
  suspense.pendingBranch = null;
871
880
  suspense.isInFallback = false;
872
- let parent2 = suspense.parent;
881
+ let parent = suspense.parent;
873
882
  let hasUnresolvedAncestor = false;
874
- while (parent2) {
875
- if (parent2.pendingBranch) {
876
- parent2.effects.push(...effects);
883
+ while (parent) {
884
+ if (parent.pendingBranch) {
885
+ parent.effects.push(...effects);
877
886
  hasUnresolvedAncestor = true;
878
887
  break;
879
888
  }
880
- parent2 = parent2.parent;
889
+ parent = parent.parent;
881
890
  }
882
891
  if (!hasUnresolvedAncestor) {
883
892
  queuePostFlushCb(effects);
884
893
  }
885
894
  suspense.effects = [];
895
+ if (isSuspensible) {
896
+ if (parentSuspense && parentSuspense.pendingBranch && parentSuspenseId === parentSuspense.pendingId) {
897
+ parentSuspense.deps--;
898
+ if (parentSuspense.deps === 0) {
899
+ parentSuspense.resolve();
900
+ }
901
+ }
902
+ }
886
903
  triggerEvent(vnode2, "onResolve");
887
904
  },
888
905
  fallback(fallbackVNode) {
@@ -976,13 +993,13 @@ function createSuspenseBoundary(vnode, parent, parentComponent, container, hidde
976
993
  }
977
994
  });
978
995
  },
979
- unmount(parentSuspense, doRemove) {
996
+ unmount(parentSuspense2, doRemove) {
980
997
  suspense.isUnmounted = true;
981
998
  if (suspense.activeBranch) {
982
999
  unmount(
983
1000
  suspense.activeBranch,
984
1001
  parentComponent,
985
- parentSuspense,
1002
+ parentSuspense2,
986
1003
  doRemove
987
1004
  );
988
1005
  }
@@ -990,7 +1007,7 @@ function createSuspenseBoundary(vnode, parent, parentComponent, container, hidde
990
1007
  unmount(
991
1008
  suspense.pendingBranch,
992
1009
  parentComponent,
993
- parentSuspense,
1010
+ parentSuspense2,
994
1011
  doRemove
995
1012
  );
996
1013
  }
@@ -2368,6 +2385,119 @@ const RuntimeCompiledPublicInstanceProxyHandlers = /* @__PURE__ */ shared.extend
2368
2385
  }
2369
2386
  );
2370
2387
 
2388
+ function defineProps() {
2389
+ return null;
2390
+ }
2391
+ function defineEmits() {
2392
+ return null;
2393
+ }
2394
+ function defineExpose(exposed) {
2395
+ }
2396
+ function defineOptions(options) {
2397
+ }
2398
+ function defineSlots() {
2399
+ return null;
2400
+ }
2401
+ function defineModel() {
2402
+ }
2403
+ function withDefaults(props, defaults) {
2404
+ return null;
2405
+ }
2406
+ function useSlots() {
2407
+ return getContext().slots;
2408
+ }
2409
+ function useAttrs() {
2410
+ return getContext().attrs;
2411
+ }
2412
+ function useModel(props, name, options) {
2413
+ const i = getCurrentInstance();
2414
+ if (options && options.local) {
2415
+ const proxy = reactivity.ref(props[name]);
2416
+ watch(
2417
+ () => props[name],
2418
+ (v) => proxy.value = v
2419
+ );
2420
+ watch(proxy, (value) => {
2421
+ if (value !== props[name]) {
2422
+ i.emit(`update:${name}`, value);
2423
+ }
2424
+ });
2425
+ return proxy;
2426
+ } else {
2427
+ return {
2428
+ __v_isRef: true,
2429
+ get value() {
2430
+ return props[name];
2431
+ },
2432
+ set value(value) {
2433
+ i.emit(`update:${name}`, value);
2434
+ }
2435
+ };
2436
+ }
2437
+ }
2438
+ function getContext() {
2439
+ const i = getCurrentInstance();
2440
+ return i.setupContext || (i.setupContext = createSetupContext(i));
2441
+ }
2442
+ function normalizePropsOrEmits(props) {
2443
+ return shared.isArray(props) ? props.reduce(
2444
+ (normalized, p) => (normalized[p] = null, normalized),
2445
+ {}
2446
+ ) : props;
2447
+ }
2448
+ function mergeDefaults(raw, defaults) {
2449
+ const props = normalizePropsOrEmits(raw);
2450
+ for (const key in defaults) {
2451
+ if (key.startsWith("__skip"))
2452
+ continue;
2453
+ let opt = props[key];
2454
+ if (opt) {
2455
+ if (shared.isArray(opt) || shared.isFunction(opt)) {
2456
+ opt = props[key] = { type: opt, default: defaults[key] };
2457
+ } else {
2458
+ opt.default = defaults[key];
2459
+ }
2460
+ } else if (opt === null) {
2461
+ opt = props[key] = { default: defaults[key] };
2462
+ } else ;
2463
+ if (opt && defaults[`__skip_${key}`]) {
2464
+ opt.skipFactory = true;
2465
+ }
2466
+ }
2467
+ return props;
2468
+ }
2469
+ function mergeModels(a, b) {
2470
+ if (!a || !b)
2471
+ return a || b;
2472
+ if (shared.isArray(a) && shared.isArray(b))
2473
+ return a.concat(b);
2474
+ return shared.extend({}, normalizePropsOrEmits(a), normalizePropsOrEmits(b));
2475
+ }
2476
+ function createPropsRestProxy(props, excludedKeys) {
2477
+ const ret = {};
2478
+ for (const key in props) {
2479
+ if (!excludedKeys.includes(key)) {
2480
+ Object.defineProperty(ret, key, {
2481
+ enumerable: true,
2482
+ get: () => props[key]
2483
+ });
2484
+ }
2485
+ }
2486
+ return ret;
2487
+ }
2488
+ function withAsyncContext(getAwaitable) {
2489
+ const ctx = getCurrentInstance();
2490
+ let awaitable = getAwaitable();
2491
+ unsetCurrentInstance();
2492
+ if (shared.isPromise(awaitable)) {
2493
+ awaitable = awaitable.catch((e) => {
2494
+ setCurrentInstance(ctx);
2495
+ throw e;
2496
+ });
2497
+ }
2498
+ return [awaitable, () => setCurrentInstance(ctx)];
2499
+ }
2500
+
2371
2501
  let shouldCacheAccess = true;
2372
2502
  function applyOptions(instance) {
2373
2503
  const options = resolveMergedOptions(instance);
@@ -2412,12 +2542,7 @@ function applyOptions(instance) {
2412
2542
  } = options;
2413
2543
  const checkDuplicateProperties = null;
2414
2544
  if (injectOptions) {
2415
- resolveInjections(
2416
- injectOptions,
2417
- ctx,
2418
- checkDuplicateProperties,
2419
- instance.appContext.config.unwrapInjectedRef
2420
- );
2545
+ resolveInjections(injectOptions, ctx, checkDuplicateProperties);
2421
2546
  }
2422
2547
  if (methods) {
2423
2548
  for (const key in methods) {
@@ -2510,7 +2635,7 @@ function applyOptions(instance) {
2510
2635
  if (directives)
2511
2636
  instance.directives = directives;
2512
2637
  }
2513
- function resolveInjections(injectOptions, ctx, checkDuplicateProperties = shared.NOOP, unwrapRef = false) {
2638
+ function resolveInjections(injectOptions, ctx, checkDuplicateProperties = shared.NOOP) {
2514
2639
  if (shared.isArray(injectOptions)) {
2515
2640
  injectOptions = normalizeInject(injectOptions);
2516
2641
  }
@@ -2532,16 +2657,12 @@ function resolveInjections(injectOptions, ctx, checkDuplicateProperties = shared
2532
2657
  injected = inject(opt);
2533
2658
  }
2534
2659
  if (reactivity.isRef(injected)) {
2535
- if (unwrapRef) {
2536
- Object.defineProperty(ctx, key, {
2537
- enumerable: true,
2538
- configurable: true,
2539
- get: () => injected.value,
2540
- set: (v) => injected.value = v
2541
- });
2542
- } else {
2543
- ctx[key] = injected;
2544
- }
2660
+ Object.defineProperty(ctx, key, {
2661
+ enumerable: true,
2662
+ configurable: true,
2663
+ get: () => injected.value,
2664
+ set: (v) => injected.value = v
2665
+ });
2545
2666
  } else {
2546
2667
  ctx[key] = injected;
2547
2668
  }
@@ -2624,10 +2745,8 @@ function mergeOptions(to, from, strats, asMixin = false) {
2624
2745
  }
2625
2746
  const internalOptionMergeStrats = {
2626
2747
  data: mergeDataFn,
2627
- props: mergeObjectOptions,
2628
- // TODO
2629
- emits: mergeObjectOptions,
2630
- // TODO
2748
+ props: mergeEmitsOrPropsOptions,
2749
+ emits: mergeEmitsOrPropsOptions,
2631
2750
  // objects
2632
2751
  methods: mergeObjectOptions,
2633
2752
  computed: mergeObjectOptions,
@@ -2686,7 +2805,21 @@ function mergeAsArray(to, from) {
2686
2805
  return to ? [...new Set([].concat(to, from))] : from;
2687
2806
  }
2688
2807
  function mergeObjectOptions(to, from) {
2689
- return to ? shared.extend(shared.extend(/* @__PURE__ */ Object.create(null), to), from) : from;
2808
+ return to ? shared.extend(/* @__PURE__ */ Object.create(null), to, from) : from;
2809
+ }
2810
+ function mergeEmitsOrPropsOptions(to, from) {
2811
+ if (to) {
2812
+ if (shared.isArray(to) && shared.isArray(from)) {
2813
+ return [.../* @__PURE__ */ new Set([...to, ...from])];
2814
+ }
2815
+ return shared.extend(
2816
+ /* @__PURE__ */ Object.create(null),
2817
+ normalizePropsOrEmits(to),
2818
+ normalizePropsOrEmits(from != null ? from : {})
2819
+ );
2820
+ } else {
2821
+ return from;
2822
+ }
2690
2823
  }
2691
2824
  function mergeWatchOptions(to, from) {
2692
2825
  if (!to)
@@ -2841,6 +2974,9 @@ function inject(key, defaultValue, treatDefaultAsFactory = false) {
2841
2974
  } else ;
2842
2975
  }
2843
2976
  }
2977
+ function hasInjectionContext() {
2978
+ return !!(currentInstance || currentRenderingInstance || currentApp);
2979
+ }
2844
2980
 
2845
2981
  function initProps(instance, rawProps, isStateful, isSSR = false) {
2846
2982
  const props = {};
@@ -5587,6 +5723,8 @@ function createComponentInstance(vnode, parent, suspense) {
5587
5723
  refs: shared.EMPTY_OBJ,
5588
5724
  setupState: shared.EMPTY_OBJ,
5589
5725
  setupContext: null,
5726
+ attrsProxy: null,
5727
+ slotsProxy: null,
5590
5728
  // suspense related
5591
5729
  suspense,
5592
5730
  suspenseId: suspense ? suspense.pendingId : 0,
@@ -5754,8 +5892,8 @@ function finishComponentSetup(instance, isSSR, skipOptions) {
5754
5892
  unsetCurrentInstance();
5755
5893
  }
5756
5894
  }
5757
- function createAttrsProxy(instance) {
5758
- return new Proxy(
5895
+ function getAttrsProxy(instance) {
5896
+ return instance.attrsProxy || (instance.attrsProxy = new Proxy(
5759
5897
  instance.attrs,
5760
5898
  {
5761
5899
  get(target, key) {
@@ -5763,17 +5901,16 @@ function createAttrsProxy(instance) {
5763
5901
  return target[key];
5764
5902
  }
5765
5903
  }
5766
- );
5904
+ ));
5767
5905
  }
5768
5906
  function createSetupContext(instance) {
5769
5907
  const expose = (exposed) => {
5770
5908
  instance.exposed = exposed || {};
5771
5909
  };
5772
- let attrs;
5773
5910
  {
5774
5911
  return {
5775
5912
  get attrs() {
5776
- return attrs || (attrs = createAttrsProxy(instance));
5913
+ return getAttrsProxy(instance);
5777
5914
  },
5778
5915
  slots: instance.slots,
5779
5916
  emit: instance.emit,
@@ -5808,119 +5945,6 @@ const computed = (getterOrOptions, debugOptions) => {
5808
5945
  return reactivity.computed(getterOrOptions, debugOptions, isInSSRComponentSetup);
5809
5946
  };
5810
5947
 
5811
- function defineProps() {
5812
- return null;
5813
- }
5814
- function defineEmits() {
5815
- return null;
5816
- }
5817
- function defineExpose(exposed) {
5818
- }
5819
- function defineOptions(options) {
5820
- }
5821
- function defineSlots() {
5822
- return null;
5823
- }
5824
- function defineModel() {
5825
- }
5826
- function withDefaults(props, defaults) {
5827
- return null;
5828
- }
5829
- function useSlots() {
5830
- return getContext().slots;
5831
- }
5832
- function useAttrs() {
5833
- return getContext().attrs;
5834
- }
5835
- function useModel(props, name, options) {
5836
- const i = getCurrentInstance();
5837
- if (options && options.local) {
5838
- const proxy = reactivity.ref(props[name]);
5839
- watch(
5840
- () => props[name],
5841
- (v) => proxy.value = v
5842
- );
5843
- watch(proxy, (value) => {
5844
- if (value !== props[name]) {
5845
- i.emit(`update:${name}`, value);
5846
- }
5847
- });
5848
- return proxy;
5849
- } else {
5850
- return {
5851
- __v_isRef: true,
5852
- get value() {
5853
- return props[name];
5854
- },
5855
- set value(value) {
5856
- i.emit(`update:${name}`, value);
5857
- }
5858
- };
5859
- }
5860
- }
5861
- function getContext() {
5862
- const i = getCurrentInstance();
5863
- return i.setupContext || (i.setupContext = createSetupContext(i));
5864
- }
5865
- function normalizePropsOrEmits(props) {
5866
- return shared.isArray(props) ? props.reduce(
5867
- (normalized, p) => (normalized[p] = {}, normalized),
5868
- {}
5869
- ) : props;
5870
- }
5871
- function mergeDefaults(raw, defaults) {
5872
- const props = normalizePropsOrEmits(raw);
5873
- for (const key in defaults) {
5874
- if (key.startsWith("__skip"))
5875
- continue;
5876
- let opt = props[key];
5877
- if (opt) {
5878
- if (shared.isArray(opt) || shared.isFunction(opt)) {
5879
- opt = props[key] = { type: opt, default: defaults[key] };
5880
- } else {
5881
- opt.default = defaults[key];
5882
- }
5883
- } else if (opt === null) {
5884
- opt = props[key] = { default: defaults[key] };
5885
- } else ;
5886
- if (opt && defaults[`__skip_${key}`]) {
5887
- opt.skipFactory = true;
5888
- }
5889
- }
5890
- return props;
5891
- }
5892
- function mergeModels(a, b) {
5893
- if (!a || !b)
5894
- return a || b;
5895
- if (shared.isArray(a) && shared.isArray(b))
5896
- return a.concat(b);
5897
- return shared.extend({}, normalizePropsOrEmits(a), normalizePropsOrEmits(b));
5898
- }
5899
- function createPropsRestProxy(props, excludedKeys) {
5900
- const ret = {};
5901
- for (const key in props) {
5902
- if (!excludedKeys.includes(key)) {
5903
- Object.defineProperty(ret, key, {
5904
- enumerable: true,
5905
- get: () => props[key]
5906
- });
5907
- }
5908
- }
5909
- return ret;
5910
- }
5911
- function withAsyncContext(getAwaitable) {
5912
- const ctx = getCurrentInstance();
5913
- let awaitable = getAwaitable();
5914
- unsetCurrentInstance();
5915
- if (shared.isPromise(awaitable)) {
5916
- awaitable = awaitable.catch((e) => {
5917
- setCurrentInstance(ctx);
5918
- throw e;
5919
- });
5920
- }
5921
- return [awaitable, () => setCurrentInstance(ctx)];
5922
- }
5923
-
5924
5948
  function h(type, propsOrChildren, children) {
5925
5949
  const l = arguments.length;
5926
5950
  if (l === 2) {
@@ -5981,7 +6005,7 @@ function isMemoSame(cached, memo) {
5981
6005
  return true;
5982
6006
  }
5983
6007
 
5984
- const version = "3.3.0-alpha.9";
6008
+ const version = "3.3.0-beta.1";
5985
6009
  const _ssrUtils = {
5986
6010
  createComponentInstance,
5987
6011
  setupComponent,
@@ -6067,6 +6091,7 @@ exports.getTransitionRawChildren = getTransitionRawChildren;
6067
6091
  exports.guardReactiveProps = guardReactiveProps;
6068
6092
  exports.h = h;
6069
6093
  exports.handleError = handleError;
6094
+ exports.hasInjectionContext = hasInjectionContext;
6070
6095
  exports.initCustomFormatter = initCustomFormatter;
6071
6096
  exports.inject = inject;
6072
6097
  exports.isMemoSame = isMemoSame;
@@ -151,6 +151,12 @@ export interface SuspenseProps {
151
151
  onPending?: () => void;
152
152
  onFallback?: () => void;
153
153
  timeout?: string | number;
154
+ /**
155
+ * Allow suspense to be captured by parent suspense
156
+ *
157
+ * @default false
158
+ */
159
+ suspensible?: boolean;
154
160
  }
155
161
  declare const SuspenseImpl: {
156
162
  name: string;
@@ -190,7 +196,7 @@ export interface SuspenseBoundary {
190
196
  registerDep(instance: ComponentInternalInstance, setupRenderEffect: SetupRenderEffectFn): void;
191
197
  unmount(parentSuspense: SuspenseBoundary | null, doRemove?: boolean): void;
192
198
  }
193
- declare function createSuspenseBoundary(vnode: VNode, parent: SuspenseBoundary | null, parentComponent: ComponentInternalInstance | null, container: RendererElement, hiddenContainer: RendererElement, anchor: RendererNode | null, isSVG: boolean, slotScopeIds: string[] | null, optimized: boolean, rendererInternals: RendererInternals, isHydrating?: boolean): SuspenseBoundary;
199
+ declare function createSuspenseBoundary(vnode: VNode, parentSuspense: SuspenseBoundary | null, parentComponent: ComponentInternalInstance | null, container: RendererElement, hiddenContainer: RendererElement, anchor: RendererNode | null, isSVG: boolean, slotScopeIds: string[] | null, optimized: boolean, rendererInternals: RendererInternals, isHydrating?: boolean): SuspenseBoundary;
194
200
  declare function hydrateSuspense(node: Node, vnode: VNode, parentComponent: ComponentInternalInstance | null, parentSuspense: SuspenseBoundary | null, isSVG: boolean, slotScopeIds: string[] | null, optimized: boolean, rendererInternals: RendererInternals, hydrateNode: (node: Node, vnode: VNode, parentComponent: ComponentInternalInstance | null, parentSuspense: SuspenseBoundary | null, slotScopeIds: string[] | null, optimized: boolean) => Node | null): Node | null;
195
201
  declare function normalizeSuspenseChildren(vnode: VNode): void;
196
202
 
@@ -660,6 +666,12 @@ export declare function provide<T>(key: InjectionKey<T> | string | number, value
660
666
  export declare function inject<T>(key: InjectionKey<T> | string): T | undefined;
661
667
  export declare function inject<T>(key: InjectionKey<T> | string, defaultValue: T, treatDefaultAsFactory?: false): T;
662
668
  export declare function inject<T>(key: InjectionKey<T> | string, defaultValue: T | (() => T), treatDefaultAsFactory: true): T;
669
+ /**
670
+ * Returns true if `inject()` can be used without warning about being called in the wrong place (e.g. outside of
671
+ * setup()). This is used by libraries that want to use `inject()` internally without triggering a warning to the end
672
+ * user. One example is `useRoute()` in `vue-router`.
673
+ */
674
+ export declare function hasInjectionContext(): boolean;
663
675
 
664
676
  export interface App<HostElement = any> {
665
677
  version: string;
@@ -713,7 +725,7 @@ export interface AppConfig {
713
725
  isCustomElement?: (tag: string) => boolean;
714
726
  /**
715
727
  * Temporary config for opt-in to unwrap injected refs.
716
- * TODO deprecate in 3.3
728
+ * @deprecated this no longer has effect. 3.3 always unwraps injected refs.
717
729
  */
718
730
  unwrapInjectedRef?: boolean;
719
731
  }
@@ -1108,6 +1120,8 @@ export interface ComponentInternalInstance {
1108
1120
  slots: InternalSlots;
1109
1121
  refs: Data;
1110
1122
  emit: EmitFn;
1123
+ attrsProxy: Data | null;
1124
+ slotsProxy: Slots | null;
1111
1125
  /* removed internal: emitted */
1112
1126
  /* removed internal: propsDefaults */
1113
1127
  /* removed internal: setupState */