vue 3.4.26 → 3.5.0-alpha.2

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * vue v3.4.26
2
+ * vue v3.5.0-alpha.2
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -450,156 +450,280 @@ class EffectScope {
450
450
  function effectScope(detached) {
451
451
  return new EffectScope(detached);
452
452
  }
453
- function recordEffectScope(effect, scope = activeEffectScope) {
454
- if (scope && scope.active) {
455
- scope.effects.push(effect);
456
- }
457
- }
458
453
  function getCurrentScope() {
459
454
  return activeEffectScope;
460
455
  }
461
- function onScopeDispose(fn) {
456
+ function onScopeDispose(fn, failSilently = false) {
462
457
  if (activeEffectScope) {
463
458
  activeEffectScope.cleanups.push(fn);
464
- } else {
459
+ } else if (!failSilently) {
465
460
  warn$2(
466
461
  `onScopeDispose() is called when there is no active effect scope to be associated with.`
467
462
  );
468
463
  }
469
464
  }
470
465
 
471
- let activeEffect;
466
+ let activeSub;
472
467
  class ReactiveEffect {
473
- constructor(fn, trigger, scheduler, scope) {
468
+ constructor(fn) {
474
469
  this.fn = fn;
475
- this.trigger = trigger;
476
- this.scheduler = scheduler;
477
- this.active = true;
478
- this.deps = [];
479
470
  /**
480
471
  * @internal
481
472
  */
482
- this._dirtyLevel = 4;
473
+ this.deps = void 0;
483
474
  /**
484
475
  * @internal
485
476
  */
486
- this._trackId = 0;
477
+ this.depsTail = void 0;
487
478
  /**
488
479
  * @internal
489
480
  */
490
- this._runnings = 0;
481
+ this.flags = 1 | 4;
491
482
  /**
492
483
  * @internal
493
484
  */
494
- this._shouldSchedule = false;
485
+ this.nextEffect = void 0;
495
486
  /**
496
487
  * @internal
497
488
  */
498
- this._depsLength = 0;
499
- recordEffectScope(this, scope);
500
- }
501
- get dirty() {
502
- if (this._dirtyLevel === 2 || this._dirtyLevel === 3) {
503
- this._dirtyLevel = 1;
504
- pauseTracking();
505
- for (let i = 0; i < this._depsLength; i++) {
506
- const dep = this.deps[i];
507
- if (dep.computed) {
508
- triggerComputed(dep.computed);
509
- if (this._dirtyLevel >= 4) {
510
- break;
511
- }
512
- }
513
- }
514
- if (this._dirtyLevel === 1) {
515
- this._dirtyLevel = 0;
516
- }
517
- resetTracking();
489
+ this.cleanup = void 0;
490
+ this.scheduler = void 0;
491
+ if (activeEffectScope && activeEffectScope.active) {
492
+ activeEffectScope.effects.push(this);
518
493
  }
519
- return this._dirtyLevel >= 4;
520
494
  }
521
- set dirty(v) {
522
- this._dirtyLevel = v ? 4 : 0;
495
+ /**
496
+ * @internal
497
+ */
498
+ notify() {
499
+ if (this.flags & 2 && !(this.flags & 32)) {
500
+ return;
501
+ }
502
+ if (this.flags & 64) {
503
+ return this.trigger();
504
+ }
505
+ if (!(this.flags & 8)) {
506
+ this.flags |= 8;
507
+ this.nextEffect = batchedEffect;
508
+ batchedEffect = this;
509
+ }
523
510
  }
524
511
  run() {
525
- this._dirtyLevel = 0;
526
- if (!this.active) {
512
+ if (!(this.flags & 1)) {
527
513
  return this.fn();
528
514
  }
529
- let lastShouldTrack = shouldTrack;
530
- let lastEffect = activeEffect;
515
+ this.flags |= 2;
516
+ cleanupEffect(this);
517
+ prepareDeps(this);
518
+ const prevEffect = activeSub;
519
+ const prevShouldTrack = shouldTrack;
520
+ activeSub = this;
521
+ shouldTrack = true;
531
522
  try {
532
- shouldTrack = true;
533
- activeEffect = this;
534
- this._runnings++;
535
- preCleanupEffect(this);
536
523
  return this.fn();
537
524
  } finally {
538
- postCleanupEffect(this);
539
- this._runnings--;
540
- activeEffect = lastEffect;
541
- shouldTrack = lastShouldTrack;
525
+ if (activeSub !== this) {
526
+ warn$2(
527
+ "Active effect was not restored correctly - this is likely a Vue internal bug."
528
+ );
529
+ }
530
+ cleanupDeps(this);
531
+ activeSub = prevEffect;
532
+ shouldTrack = prevShouldTrack;
533
+ this.flags &= ~2;
542
534
  }
543
535
  }
544
536
  stop() {
545
- if (this.active) {
546
- preCleanupEffect(this);
547
- postCleanupEffect(this);
537
+ if (this.flags & 1) {
538
+ for (let link = this.deps; link; link = link.nextDep) {
539
+ removeSub(link);
540
+ }
541
+ this.deps = this.depsTail = void 0;
542
+ cleanupEffect(this);
548
543
  this.onStop && this.onStop();
549
- this.active = false;
544
+ this.flags &= ~1;
545
+ }
546
+ }
547
+ trigger() {
548
+ if (this.scheduler) {
549
+ this.scheduler();
550
+ } else {
551
+ this.runIfDirty();
550
552
  }
551
553
  }
554
+ /**
555
+ * @internal
556
+ */
557
+ runIfDirty() {
558
+ if (isDirty(this)) {
559
+ this.run();
560
+ }
561
+ }
562
+ get dirty() {
563
+ return isDirty(this);
564
+ }
565
+ }
566
+ let batchDepth = 0;
567
+ let batchedEffect;
568
+ function startBatch() {
569
+ batchDepth++;
570
+ }
571
+ function endBatch() {
572
+ if (batchDepth > 1) {
573
+ batchDepth--;
574
+ return;
575
+ }
576
+ let error;
577
+ while (batchedEffect) {
578
+ let e = batchedEffect;
579
+ batchedEffect = void 0;
580
+ while (e) {
581
+ const next = e.nextEffect;
582
+ e.nextEffect = void 0;
583
+ e.flags &= ~8;
584
+ if (e.flags & 1) {
585
+ try {
586
+ e.trigger();
587
+ } catch (err) {
588
+ if (!error)
589
+ error = err;
590
+ }
591
+ }
592
+ e = next;
593
+ }
594
+ }
595
+ batchDepth--;
596
+ if (error)
597
+ throw error;
598
+ }
599
+ function prepareDeps(sub) {
600
+ for (let link = sub.deps; link; link = link.nextDep) {
601
+ link.version = -1;
602
+ link.prevActiveLink = link.dep.activeLink;
603
+ link.dep.activeLink = link;
604
+ }
552
605
  }
553
- function triggerComputed(computed) {
554
- return computed.value;
606
+ function cleanupDeps(sub) {
607
+ let head;
608
+ let tail = sub.depsTail;
609
+ for (let link = tail; link; link = link.prevDep) {
610
+ if (link.version === -1) {
611
+ if (link === tail)
612
+ tail = link.prevDep;
613
+ removeSub(link);
614
+ removeDep(link);
615
+ } else {
616
+ head = link;
617
+ }
618
+ link.dep.activeLink = link.prevActiveLink;
619
+ link.prevActiveLink = void 0;
620
+ }
621
+ sub.deps = head;
622
+ sub.depsTail = tail;
555
623
  }
556
- function preCleanupEffect(effect2) {
557
- effect2._trackId++;
558
- effect2._depsLength = 0;
624
+ function isDirty(sub) {
625
+ for (let link = sub.deps; link; link = link.nextDep) {
626
+ if (link.dep.version !== link.version || link.dep.computed && refreshComputed(link.dep.computed) === false || link.dep.version !== link.version) {
627
+ return true;
628
+ }
629
+ }
630
+ if (sub._dirty) {
631
+ return true;
632
+ }
633
+ return false;
559
634
  }
560
- function postCleanupEffect(effect2) {
561
- if (effect2.deps.length > effect2._depsLength) {
562
- for (let i = effect2._depsLength; i < effect2.deps.length; i++) {
563
- cleanupDepEffect(effect2.deps[i], effect2);
635
+ function refreshComputed(computed) {
636
+ if (computed.flags & 2) {
637
+ return false;
638
+ }
639
+ if (computed.flags & 4 && !(computed.flags & 16)) {
640
+ return;
641
+ }
642
+ computed.flags &= ~16;
643
+ if (computed.globalVersion === globalVersion) {
644
+ return;
645
+ }
646
+ computed.globalVersion = globalVersion;
647
+ const dep = computed.dep;
648
+ computed.flags |= 2;
649
+ if (dep.version > 0 && !computed.isSSR && !isDirty(computed)) {
650
+ computed.flags &= ~2;
651
+ return;
652
+ }
653
+ const prevSub = activeSub;
654
+ const prevShouldTrack = shouldTrack;
655
+ activeSub = computed;
656
+ shouldTrack = true;
657
+ try {
658
+ prepareDeps(computed);
659
+ const value = computed.fn();
660
+ if (dep.version === 0 || hasChanged(value, computed._value)) {
661
+ computed._value = value;
662
+ dep.version++;
564
663
  }
565
- effect2.deps.length = effect2._depsLength;
664
+ } catch (err) {
665
+ dep.version++;
666
+ throw err;
667
+ } finally {
668
+ activeSub = prevSub;
669
+ shouldTrack = prevShouldTrack;
670
+ cleanupDeps(computed);
671
+ computed.flags &= ~2;
566
672
  }
567
673
  }
568
- function cleanupDepEffect(dep, effect2) {
569
- const trackId = dep.get(effect2);
570
- if (trackId !== void 0 && effect2._trackId !== trackId) {
571
- dep.delete(effect2);
572
- if (dep.size === 0) {
573
- dep.cleanup();
674
+ function removeSub(link) {
675
+ const { dep, prevSub, nextSub } = link;
676
+ if (prevSub) {
677
+ prevSub.nextSub = nextSub;
678
+ link.prevSub = void 0;
679
+ }
680
+ if (nextSub) {
681
+ nextSub.prevSub = prevSub;
682
+ link.nextSub = void 0;
683
+ }
684
+ if (dep.subs === link) {
685
+ dep.subs = prevSub;
686
+ }
687
+ if (!dep.subs && dep.computed) {
688
+ dep.computed.flags &= ~4;
689
+ for (let l = dep.computed.deps; l; l = l.nextDep) {
690
+ removeSub(l);
574
691
  }
575
692
  }
576
693
  }
694
+ function removeDep(link) {
695
+ const { prevDep, nextDep } = link;
696
+ if (prevDep) {
697
+ prevDep.nextDep = nextDep;
698
+ link.prevDep = void 0;
699
+ }
700
+ if (nextDep) {
701
+ nextDep.prevDep = prevDep;
702
+ link.nextDep = void 0;
703
+ }
704
+ }
577
705
  function effect(fn, options) {
578
706
  if (fn.effect instanceof ReactiveEffect) {
579
707
  fn = fn.effect.fn;
580
708
  }
581
- const _effect = new ReactiveEffect(fn, NOOP, () => {
582
- if (_effect.dirty) {
583
- _effect.run();
584
- }
585
- });
709
+ const e = new ReactiveEffect(fn);
586
710
  if (options) {
587
- extend(_effect, options);
588
- if (options.scope)
589
- recordEffectScope(_effect, options.scope);
711
+ extend(e, options);
590
712
  }
591
- if (!options || !options.lazy) {
592
- _effect.run();
713
+ try {
714
+ e.run();
715
+ } catch (err) {
716
+ e.stop();
717
+ throw err;
593
718
  }
594
- const runner = _effect.run.bind(_effect);
595
- runner.effect = _effect;
719
+ const runner = e.run.bind(e);
720
+ runner.effect = e;
596
721
  return runner;
597
722
  }
598
723
  function stop(runner) {
599
724
  runner.effect.stop();
600
725
  }
601
726
  let shouldTrack = true;
602
- let pauseScheduleStack = 0;
603
727
  const trackStack = [];
604
728
  function pauseTracking() {
605
729
  trackStack.push(shouldTrack);
@@ -609,192 +733,414 @@ function resetTracking() {
609
733
  const last = trackStack.pop();
610
734
  shouldTrack = last === void 0 ? true : last;
611
735
  }
612
- function pauseScheduling() {
613
- pauseScheduleStack++;
614
- }
615
- function resetScheduling() {
616
- pauseScheduleStack--;
617
- while (!pauseScheduleStack && queueEffectSchedulers.length) {
618
- queueEffectSchedulers.shift()();
736
+ function cleanupEffect(e) {
737
+ const { cleanup } = e;
738
+ e.cleanup = void 0;
739
+ if (cleanup) {
740
+ const prevSub = activeSub;
741
+ activeSub = void 0;
742
+ try {
743
+ cleanup();
744
+ } finally {
745
+ activeSub = prevSub;
746
+ }
619
747
  }
620
748
  }
621
- function trackEffect(effect2, dep, debuggerEventExtraInfo) {
622
- var _a;
623
- if (dep.get(effect2) !== effect2._trackId) {
624
- dep.set(effect2, effect2._trackId);
625
- const oldDep = effect2.deps[effect2._depsLength];
626
- if (oldDep !== dep) {
627
- if (oldDep) {
628
- cleanupDepEffect(oldDep, effect2);
629
- }
630
- effect2.deps[effect2._depsLength++] = dep;
631
- } else {
632
- effect2._depsLength++;
633
- }
749
+
750
+ let globalVersion = 0;
751
+ class Dep {
752
+ constructor(computed) {
753
+ this.computed = computed;
754
+ this.version = 0;
755
+ /**
756
+ * Link between this dep and the current active effect
757
+ */
758
+ this.activeLink = void 0;
759
+ /**
760
+ * Doubly linked list representing the subscribing effects (tail)
761
+ */
762
+ this.subs = void 0;
634
763
  {
635
- (_a = effect2.onTrack) == null ? void 0 : _a.call(effect2, extend({ effect: effect2 }, debuggerEventExtraInfo));
764
+ this.subsHead = void 0;
636
765
  }
637
766
  }
638
- }
639
- const queueEffectSchedulers = [];
640
- function triggerEffects(dep, dirtyLevel, debuggerEventExtraInfo) {
641
- var _a;
642
- pauseScheduling();
643
- for (const effect2 of dep.keys()) {
644
- let tracking;
645
- if (effect2._dirtyLevel < dirtyLevel && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
646
- effect2._shouldSchedule || (effect2._shouldSchedule = effect2._dirtyLevel === 0);
647
- effect2._dirtyLevel = dirtyLevel;
648
- }
649
- if (effect2._shouldSchedule && (tracking != null ? tracking : tracking = dep.get(effect2) === effect2._trackId)) {
650
- {
651
- (_a = effect2.onTrigger) == null ? void 0 : _a.call(effect2, extend({ effect: effect2 }, debuggerEventExtraInfo));
767
+ track(debugInfo) {
768
+ if (!activeSub || !shouldTrack) {
769
+ return;
770
+ }
771
+ let link = this.activeLink;
772
+ if (link === void 0 || link.sub !== activeSub) {
773
+ link = this.activeLink = {
774
+ dep: this,
775
+ sub: activeSub,
776
+ version: this.version,
777
+ nextDep: void 0,
778
+ prevDep: void 0,
779
+ nextSub: void 0,
780
+ prevSub: void 0,
781
+ prevActiveLink: void 0
782
+ };
783
+ if (!activeSub.deps) {
784
+ activeSub.deps = activeSub.depsTail = link;
785
+ } else {
786
+ link.prevDep = activeSub.depsTail;
787
+ activeSub.depsTail.nextDep = link;
788
+ activeSub.depsTail = link;
652
789
  }
653
- effect2.trigger();
654
- if ((!effect2._runnings || effect2.allowRecurse) && effect2._dirtyLevel !== 2) {
655
- effect2._shouldSchedule = false;
656
- if (effect2.scheduler) {
657
- queueEffectSchedulers.push(effect2.scheduler);
790
+ if (activeSub.flags & 4) {
791
+ addSub(link);
792
+ }
793
+ } else if (link.version === -1) {
794
+ link.version = this.version;
795
+ if (link.nextDep) {
796
+ const next = link.nextDep;
797
+ next.prevDep = link.prevDep;
798
+ if (link.prevDep) {
799
+ link.prevDep.nextDep = next;
800
+ }
801
+ link.prevDep = activeSub.depsTail;
802
+ link.nextDep = void 0;
803
+ activeSub.depsTail.nextDep = link;
804
+ activeSub.depsTail = link;
805
+ if (activeSub.deps === link) {
806
+ activeSub.deps = next;
658
807
  }
659
808
  }
660
809
  }
810
+ if (activeSub.onTrack) {
811
+ activeSub.onTrack(
812
+ extend(
813
+ {
814
+ effect: activeSub
815
+ },
816
+ debugInfo
817
+ )
818
+ );
819
+ }
820
+ return link;
821
+ }
822
+ trigger(debugInfo) {
823
+ this.version++;
824
+ globalVersion++;
825
+ this.notify(debugInfo);
826
+ }
827
+ notify(debugInfo) {
828
+ startBatch();
829
+ try {
830
+ if (true) {
831
+ for (let head = this.subsHead; head; head = head.nextSub) {
832
+ if (head.sub.onTrigger && !(head.sub.flags & 8)) {
833
+ head.sub.onTrigger(
834
+ extend(
835
+ {
836
+ effect: head.sub
837
+ },
838
+ debugInfo
839
+ )
840
+ );
841
+ }
842
+ }
843
+ }
844
+ for (let link = this.subs; link; link = link.prevSub) {
845
+ link.sub.notify();
846
+ }
847
+ } finally {
848
+ endBatch();
849
+ }
661
850
  }
662
- resetScheduling();
663
851
  }
664
-
665
- const createDep = (cleanup, computed) => {
666
- const dep = /* @__PURE__ */ new Map();
667
- dep.cleanup = cleanup;
668
- dep.computed = computed;
669
- return dep;
670
- };
671
-
852
+ function addSub(link) {
853
+ const computed = link.dep.computed;
854
+ if (computed && !link.dep.subs) {
855
+ computed.flags |= 4 | 16;
856
+ for (let l = computed.deps; l; l = l.nextDep) {
857
+ addSub(l);
858
+ }
859
+ }
860
+ const currentTail = link.dep.subs;
861
+ if (currentTail !== link) {
862
+ link.prevSub = currentTail;
863
+ if (currentTail)
864
+ currentTail.nextSub = link;
865
+ }
866
+ if (link.dep.subsHead === void 0) {
867
+ link.dep.subsHead = link;
868
+ }
869
+ link.dep.subs = link;
870
+ }
672
871
  const targetMap = /* @__PURE__ */ new WeakMap();
673
- const ITERATE_KEY = Symbol("iterate" );
674
- const MAP_KEY_ITERATE_KEY = Symbol("Map key iterate" );
872
+ const ITERATE_KEY = Symbol("Object iterate" );
873
+ const MAP_KEY_ITERATE_KEY = Symbol("Map keys iterate" );
874
+ const ARRAY_ITERATE_KEY = Symbol("Array iterate" );
675
875
  function track(target, type, key) {
676
- if (shouldTrack && activeEffect) {
876
+ if (shouldTrack && activeSub) {
677
877
  let depsMap = targetMap.get(target);
678
878
  if (!depsMap) {
679
879
  targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
680
880
  }
681
881
  let dep = depsMap.get(key);
682
882
  if (!dep) {
683
- depsMap.set(key, dep = createDep(() => depsMap.delete(key)));
883
+ depsMap.set(key, dep = new Dep());
684
884
  }
685
- trackEffect(
686
- activeEffect,
687
- dep,
688
- {
885
+ {
886
+ dep.track({
689
887
  target,
690
888
  type,
691
889
  key
692
- }
693
- );
890
+ });
891
+ }
694
892
  }
695
893
  }
696
894
  function trigger(target, type, key, newValue, oldValue, oldTarget) {
697
895
  const depsMap = targetMap.get(target);
698
896
  if (!depsMap) {
897
+ globalVersion++;
699
898
  return;
700
899
  }
701
900
  let deps = [];
702
901
  if (type === "clear") {
703
902
  deps = [...depsMap.values()];
704
- } else if (key === "length" && isArray(target)) {
705
- const newLength = Number(newValue);
706
- depsMap.forEach((dep, key2) => {
707
- if (key2 === "length" || !isSymbol(key2) && key2 >= newLength) {
708
- deps.push(dep);
709
- }
710
- });
711
903
  } else {
712
- if (key !== void 0) {
713
- deps.push(depsMap.get(key));
714
- }
715
- switch (type) {
716
- case "add":
717
- if (!isArray(target)) {
718
- deps.push(depsMap.get(ITERATE_KEY));
719
- if (isMap(target)) {
720
- deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
721
- }
722
- } else if (isIntegerKey(key)) {
723
- deps.push(depsMap.get("length"));
904
+ const targetIsArray = isArray(target);
905
+ const isArrayIndex = targetIsArray && isIntegerKey(key);
906
+ if (targetIsArray && key === "length") {
907
+ const newLength = Number(newValue);
908
+ depsMap.forEach((dep, key2) => {
909
+ if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !isSymbol(key2) && key2 >= newLength) {
910
+ deps.push(dep);
724
911
  }
725
- break;
726
- case "delete":
727
- if (!isArray(target)) {
728
- deps.push(depsMap.get(ITERATE_KEY));
912
+ });
913
+ } else {
914
+ const push = (dep) => dep && deps.push(dep);
915
+ if (key !== void 0) {
916
+ push(depsMap.get(key));
917
+ }
918
+ if (isArrayIndex) {
919
+ push(depsMap.get(ARRAY_ITERATE_KEY));
920
+ }
921
+ switch (type) {
922
+ case "add":
923
+ if (!targetIsArray) {
924
+ push(depsMap.get(ITERATE_KEY));
925
+ if (isMap(target)) {
926
+ push(depsMap.get(MAP_KEY_ITERATE_KEY));
927
+ }
928
+ } else if (isArrayIndex) {
929
+ push(depsMap.get("length"));
930
+ }
931
+ break;
932
+ case "delete":
933
+ if (!targetIsArray) {
934
+ push(depsMap.get(ITERATE_KEY));
935
+ if (isMap(target)) {
936
+ push(depsMap.get(MAP_KEY_ITERATE_KEY));
937
+ }
938
+ }
939
+ break;
940
+ case "set":
729
941
  if (isMap(target)) {
730
- deps.push(depsMap.get(MAP_KEY_ITERATE_KEY));
942
+ push(depsMap.get(ITERATE_KEY));
731
943
  }
732
- }
733
- break;
734
- case "set":
735
- if (isMap(target)) {
736
- deps.push(depsMap.get(ITERATE_KEY));
737
- }
738
- break;
944
+ break;
945
+ }
739
946
  }
740
947
  }
741
- pauseScheduling();
948
+ startBatch();
742
949
  for (const dep of deps) {
743
- if (dep) {
744
- triggerEffects(
745
- dep,
746
- 4,
747
- {
748
- target,
749
- type,
750
- key,
751
- newValue,
752
- oldValue,
753
- oldTarget
754
- }
755
- );
950
+ {
951
+ dep.trigger({
952
+ target,
953
+ type,
954
+ key,
955
+ newValue,
956
+ oldValue,
957
+ oldTarget
958
+ });
756
959
  }
757
960
  }
758
- resetScheduling();
961
+ endBatch();
759
962
  }
760
963
  function getDepFromReactive(object, key) {
761
- const depsMap = targetMap.get(object);
762
- return depsMap && depsMap.get(key);
964
+ var _a;
965
+ return (_a = targetMap.get(object)) == null ? void 0 : _a.get(key);
966
+ }
967
+
968
+ function reactiveReadArray(array) {
969
+ const raw = toRaw(array);
970
+ if (raw === array)
971
+ return raw;
972
+ track(raw, "iterate", ARRAY_ITERATE_KEY);
973
+ return isShallow(array) ? raw : raw.map(toReactive);
974
+ }
975
+ function shallowReadArray(arr) {
976
+ track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
977
+ return arr;
978
+ }
979
+ const arrayInstrumentations = {
980
+ __proto__: null,
981
+ [Symbol.iterator]() {
982
+ return iterator(this, Symbol.iterator, toReactive);
983
+ },
984
+ concat(...args) {
985
+ return reactiveReadArray(this).concat(
986
+ ...args.map((x) => reactiveReadArray(x))
987
+ );
988
+ },
989
+ entries() {
990
+ return iterator(this, "entries", (value) => {
991
+ value[1] = toReactive(value[1]);
992
+ return value;
993
+ });
994
+ },
995
+ every(fn, thisArg) {
996
+ return apply(this, "every", fn, thisArg);
997
+ },
998
+ filter(fn, thisArg) {
999
+ const result = apply(this, "filter", fn, thisArg);
1000
+ return isProxy(this) && !isShallow(this) ? result.map(toReactive) : result;
1001
+ },
1002
+ find(fn, thisArg) {
1003
+ const result = apply(this, "find", fn, thisArg);
1004
+ return isProxy(this) && !isShallow(this) ? toReactive(result) : result;
1005
+ },
1006
+ findIndex(fn, thisArg) {
1007
+ return apply(this, "findIndex", fn, thisArg);
1008
+ },
1009
+ findLast(fn, thisArg) {
1010
+ const result = apply(this, "findLast", fn, thisArg);
1011
+ return isProxy(this) && !isShallow(this) ? toReactive(result) : result;
1012
+ },
1013
+ findLastIndex(fn, thisArg) {
1014
+ return apply(this, "findLastIndex", fn, thisArg);
1015
+ },
1016
+ // flat, flatMap could benefit from ARRAY_ITERATE but are not straight-forward to implement
1017
+ forEach(fn, thisArg) {
1018
+ return apply(this, "forEach", fn, thisArg);
1019
+ },
1020
+ includes(...args) {
1021
+ return searchProxy(this, "includes", args);
1022
+ },
1023
+ indexOf(...args) {
1024
+ return searchProxy(this, "indexOf", args);
1025
+ },
1026
+ join(separator) {
1027
+ return reactiveReadArray(this).join(separator);
1028
+ },
1029
+ // keys() iterator only reads `length`, no optimisation required
1030
+ lastIndexOf(...args) {
1031
+ return searchProxy(this, "lastIndexOf", args);
1032
+ },
1033
+ map(fn, thisArg) {
1034
+ return apply(this, "map", fn, thisArg);
1035
+ },
1036
+ pop() {
1037
+ return noTracking(this, "pop");
1038
+ },
1039
+ push(...args) {
1040
+ return noTracking(this, "push", args);
1041
+ },
1042
+ reduce(fn, ...args) {
1043
+ return reduce(this, "reduce", fn, args);
1044
+ },
1045
+ reduceRight(fn, ...args) {
1046
+ return reduce(this, "reduceRight", fn, args);
1047
+ },
1048
+ shift() {
1049
+ return noTracking(this, "shift");
1050
+ },
1051
+ // slice could use ARRAY_ITERATE but also seems to beg for range tracking
1052
+ some(fn, thisArg) {
1053
+ return apply(this, "some", fn, thisArg);
1054
+ },
1055
+ splice(...args) {
1056
+ return noTracking(this, "splice", args);
1057
+ },
1058
+ toReversed() {
1059
+ return reactiveReadArray(this).toReversed();
1060
+ },
1061
+ toSorted(comparer) {
1062
+ return reactiveReadArray(this).toSorted(comparer);
1063
+ },
1064
+ toSpliced(...args) {
1065
+ return reactiveReadArray(this).toSpliced(...args);
1066
+ },
1067
+ unshift(...args) {
1068
+ return noTracking(this, "unshift", args);
1069
+ },
1070
+ values() {
1071
+ return iterator(this, "values", toReactive);
1072
+ }
1073
+ };
1074
+ function iterator(self, method, wrapValue) {
1075
+ const arr = shallowReadArray(self);
1076
+ const iter = arr[method]();
1077
+ if (arr !== self && !isShallow(self)) {
1078
+ iter._next = iter.next;
1079
+ iter.next = () => {
1080
+ const result = iter._next();
1081
+ if (result.value) {
1082
+ result.value = wrapValue(result.value);
1083
+ }
1084
+ return result;
1085
+ };
1086
+ }
1087
+ return iter;
1088
+ }
1089
+ function apply(self, method, fn, thisArg) {
1090
+ const arr = shallowReadArray(self);
1091
+ let wrappedFn = fn;
1092
+ if (arr !== self) {
1093
+ if (!isShallow(self)) {
1094
+ wrappedFn = function(item, index) {
1095
+ return fn.call(this, toReactive(item), index, self);
1096
+ };
1097
+ } else if (fn.length > 2) {
1098
+ wrappedFn = function(item, index) {
1099
+ return fn.call(this, item, index, self);
1100
+ };
1101
+ }
1102
+ }
1103
+ return arr[method](wrappedFn, thisArg);
1104
+ }
1105
+ function reduce(self, method, fn, args) {
1106
+ const arr = shallowReadArray(self);
1107
+ let wrappedFn = fn;
1108
+ if (arr !== self) {
1109
+ if (!isShallow(self)) {
1110
+ wrappedFn = function(acc, item, index) {
1111
+ return fn.call(this, acc, toReactive(item), index, self);
1112
+ };
1113
+ } else if (fn.length > 3) {
1114
+ wrappedFn = function(acc, item, index) {
1115
+ return fn.call(this, acc, item, index, self);
1116
+ };
1117
+ }
1118
+ }
1119
+ return arr[method](wrappedFn, ...args);
1120
+ }
1121
+ function searchProxy(self, method, args) {
1122
+ const arr = toRaw(self);
1123
+ track(arr, "iterate", ARRAY_ITERATE_KEY);
1124
+ const res = arr[method](...args);
1125
+ if ((res === -1 || res === false) && isProxy(args[0])) {
1126
+ args[0] = toRaw(args[0]);
1127
+ return arr[method](...args);
1128
+ }
1129
+ return res;
1130
+ }
1131
+ function noTracking(self, method, args = []) {
1132
+ pauseTracking();
1133
+ startBatch();
1134
+ const res = toRaw(self)[method].apply(self, args);
1135
+ endBatch();
1136
+ resetTracking();
1137
+ return res;
763
1138
  }
764
1139
 
765
1140
  const isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
766
1141
  const builtInSymbols = new Set(
767
1142
  /* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol)
768
1143
  );
769
- const arrayInstrumentations = /* @__PURE__ */ createArrayInstrumentations();
770
- function createArrayInstrumentations() {
771
- const instrumentations = {};
772
- ["includes", "indexOf", "lastIndexOf"].forEach((key) => {
773
- instrumentations[key] = function(...args) {
774
- const arr = toRaw(this);
775
- for (let i = 0, l = this.length; i < l; i++) {
776
- track(arr, "get", i + "");
777
- }
778
- const res = arr[key](...args);
779
- if (res === -1 || res === false) {
780
- return arr[key](...args.map(toRaw));
781
- } else {
782
- return res;
783
- }
784
- };
785
- });
786
- ["push", "pop", "shift", "unshift", "splice"].forEach((key) => {
787
- instrumentations[key] = function(...args) {
788
- pauseTracking();
789
- pauseScheduling();
790
- const res = toRaw(this)[key].apply(this, args);
791
- resetScheduling();
792
- resetTracking();
793
- return res;
794
- };
795
- });
796
- return instrumentations;
797
- }
798
1144
  function hasOwnProperty(key) {
799
1145
  if (!isSymbol(key))
800
1146
  key = String(key);
@@ -825,14 +1171,22 @@ class BaseReactiveHandler {
825
1171
  }
826
1172
  const targetIsArray = isArray(target);
827
1173
  if (!isReadonly2) {
828
- if (targetIsArray && hasOwn(arrayInstrumentations, key)) {
829
- return Reflect.get(arrayInstrumentations, key, receiver);
1174
+ let fn;
1175
+ if (targetIsArray && (fn = arrayInstrumentations[key])) {
1176
+ return fn;
830
1177
  }
831
1178
  if (key === "hasOwnProperty") {
832
1179
  return hasOwnProperty;
833
1180
  }
834
1181
  }
835
- const res = Reflect.get(target, key, receiver);
1182
+ const res = Reflect.get(
1183
+ target,
1184
+ key,
1185
+ // if this is a proxy wrapping a ref, return methods using the raw ref
1186
+ // as receiver so that we don't have to call `toRaw` on the ref in all
1187
+ // its class methods
1188
+ isRef(target) ? target : receiver
1189
+ );
836
1190
  if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
837
1191
  return res;
838
1192
  }
@@ -1331,110 +1685,8 @@ function markRaw(value) {
1331
1685
  const toReactive = (value) => isObject(value) ? reactive(value) : value;
1332
1686
  const toReadonly = (value) => isObject(value) ? readonly(value) : value;
1333
1687
 
1334
- const COMPUTED_SIDE_EFFECT_WARN = `Computed is still dirty after getter evaluation, likely because a computed is mutating its own dependency in its getter. State mutations in computed getters should be avoided. Check the docs for more details: https://vuejs.org/guide/essentials/computed.html#getters-should-be-side-effect-free`;
1335
- class ComputedRefImpl {
1336
- constructor(getter, _setter, isReadonly, isSSR) {
1337
- this.getter = getter;
1338
- this._setter = _setter;
1339
- this.dep = void 0;
1340
- this.__v_isRef = true;
1341
- this["__v_isReadonly"] = false;
1342
- this.effect = new ReactiveEffect(
1343
- () => getter(this._value),
1344
- () => triggerRefValue(
1345
- this,
1346
- this.effect._dirtyLevel === 2 ? 2 : 3
1347
- )
1348
- );
1349
- this.effect.computed = this;
1350
- this.effect.active = this._cacheable = !isSSR;
1351
- this["__v_isReadonly"] = isReadonly;
1352
- }
1353
- get value() {
1354
- const self = toRaw(this);
1355
- if ((!self._cacheable || self.effect.dirty) && hasChanged(self._value, self._value = self.effect.run())) {
1356
- triggerRefValue(self, 4);
1357
- }
1358
- trackRefValue(self);
1359
- if (self.effect._dirtyLevel >= 2) {
1360
- if (this._warnRecursive) {
1361
- warn$2(COMPUTED_SIDE_EFFECT_WARN, `
1362
-
1363
- getter: `, this.getter);
1364
- }
1365
- triggerRefValue(self, 2);
1366
- }
1367
- return self._value;
1368
- }
1369
- set value(newValue) {
1370
- this._setter(newValue);
1371
- }
1372
- // #region polyfill _dirty for backward compatibility third party code for Vue <= 3.3.x
1373
- get _dirty() {
1374
- return this.effect.dirty;
1375
- }
1376
- set _dirty(v) {
1377
- this.effect.dirty = v;
1378
- }
1379
- // #endregion
1380
- }
1381
- function computed$1(getterOrOptions, debugOptions, isSSR = false) {
1382
- let getter;
1383
- let setter;
1384
- const onlyGetter = isFunction(getterOrOptions);
1385
- if (onlyGetter) {
1386
- getter = getterOrOptions;
1387
- setter = () => {
1388
- warn$2("Write operation failed: computed value is readonly");
1389
- } ;
1390
- } else {
1391
- getter = getterOrOptions.get;
1392
- setter = getterOrOptions.set;
1393
- }
1394
- const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter, isSSR);
1395
- if (debugOptions && !isSSR) {
1396
- cRef.effect.onTrack = debugOptions.onTrack;
1397
- cRef.effect.onTrigger = debugOptions.onTrigger;
1398
- }
1399
- return cRef;
1400
- }
1401
-
1402
- function trackRefValue(ref2) {
1403
- var _a;
1404
- if (shouldTrack && activeEffect) {
1405
- ref2 = toRaw(ref2);
1406
- trackEffect(
1407
- activeEffect,
1408
- (_a = ref2.dep) != null ? _a : ref2.dep = createDep(
1409
- () => ref2.dep = void 0,
1410
- ref2 instanceof ComputedRefImpl ? ref2 : void 0
1411
- ),
1412
- {
1413
- target: ref2,
1414
- type: "get",
1415
- key: "value"
1416
- }
1417
- );
1418
- }
1419
- }
1420
- function triggerRefValue(ref2, dirtyLevel = 4, newVal) {
1421
- ref2 = toRaw(ref2);
1422
- const dep = ref2.dep;
1423
- if (dep) {
1424
- triggerEffects(
1425
- dep,
1426
- dirtyLevel,
1427
- {
1428
- target: ref2,
1429
- type: "set",
1430
- key: "value",
1431
- newValue: newVal
1432
- }
1433
- );
1434
- }
1435
- }
1436
1688
  function isRef(r) {
1437
- return !!(r && r.__v_isRef === true);
1689
+ return r ? r.__v_isRef === true : false;
1438
1690
  }
1439
1691
  function ref(value) {
1440
1692
  return createRef(value, false);
@@ -1451,27 +1703,49 @@ function createRef(rawValue, shallow) {
1451
1703
  class RefImpl {
1452
1704
  constructor(value, __v_isShallow) {
1453
1705
  this.__v_isShallow = __v_isShallow;
1454
- this.dep = void 0;
1706
+ this.dep = new Dep();
1455
1707
  this.__v_isRef = true;
1456
1708
  this._rawValue = __v_isShallow ? value : toRaw(value);
1457
1709
  this._value = __v_isShallow ? value : toReactive(value);
1458
1710
  }
1459
1711
  get value() {
1460
- trackRefValue(this);
1712
+ {
1713
+ this.dep.track({
1714
+ target: this,
1715
+ type: "get",
1716
+ key: "value"
1717
+ });
1718
+ }
1461
1719
  return this._value;
1462
1720
  }
1463
- set value(newVal) {
1464
- const useDirectValue = this.__v_isShallow || isShallow(newVal) || isReadonly(newVal);
1465
- newVal = useDirectValue ? newVal : toRaw(newVal);
1466
- if (hasChanged(newVal, this._rawValue)) {
1467
- this._rawValue = newVal;
1468
- this._value = useDirectValue ? newVal : toReactive(newVal);
1469
- triggerRefValue(this, 4, newVal);
1721
+ set value(newValue) {
1722
+ const oldValue = this._rawValue;
1723
+ const useDirectValue = this.__v_isShallow || isShallow(newValue) || isReadonly(newValue);
1724
+ newValue = useDirectValue ? newValue : toRaw(newValue);
1725
+ if (hasChanged(newValue, oldValue)) {
1726
+ this._rawValue = newValue;
1727
+ this._value = useDirectValue ? newValue : toReactive(newValue);
1728
+ {
1729
+ this.dep.trigger({
1730
+ target: this,
1731
+ type: "set",
1732
+ key: "value",
1733
+ newValue,
1734
+ oldValue
1735
+ });
1736
+ }
1470
1737
  }
1471
1738
  }
1472
1739
  }
1473
1740
  function triggerRef(ref2) {
1474
- triggerRefValue(ref2, 4, ref2.value );
1741
+ {
1742
+ ref2.dep.trigger({
1743
+ target: ref2,
1744
+ type: "set",
1745
+ key: "value",
1746
+ newValue: ref2._value
1747
+ });
1748
+ }
1475
1749
  }
1476
1750
  function unref(ref2) {
1477
1751
  return isRef(ref2) ? ref2.value : ref2;
@@ -1496,12 +1770,9 @@ function proxyRefs(objectWithRefs) {
1496
1770
  }
1497
1771
  class CustomRefImpl {
1498
1772
  constructor(factory) {
1499
- this.dep = void 0;
1500
1773
  this.__v_isRef = true;
1501
- const { get, set } = factory(
1502
- () => trackRefValue(this),
1503
- () => triggerRefValue(this)
1504
- );
1774
+ const dep = this.dep = new Dep();
1775
+ const { get, set } = factory(dep.track.bind(dep), dep.trigger.bind(dep));
1505
1776
  this._get = get;
1506
1777
  this._set = set;
1507
1778
  }
@@ -1569,6 +1840,90 @@ function propertyToRef(source, key, defaultValue) {
1569
1840
  return isRef(val) ? val : new ObjectRefImpl(source, key, defaultValue);
1570
1841
  }
1571
1842
 
1843
+ class ComputedRefImpl {
1844
+ constructor(fn, setter, isSSR) {
1845
+ this.fn = fn;
1846
+ this.setter = setter;
1847
+ /**
1848
+ * @internal
1849
+ */
1850
+ this._value = void 0;
1851
+ /**
1852
+ * @internal
1853
+ */
1854
+ this.dep = new Dep(this);
1855
+ /**
1856
+ * @internal
1857
+ */
1858
+ this.__v_isRef = true;
1859
+ // A computed is also a subscriber that tracks other deps
1860
+ /**
1861
+ * @internal
1862
+ */
1863
+ this.deps = void 0;
1864
+ /**
1865
+ * @internal
1866
+ */
1867
+ this.depsTail = void 0;
1868
+ /**
1869
+ * @internal
1870
+ */
1871
+ this.flags = 16;
1872
+ /**
1873
+ * @internal
1874
+ */
1875
+ this.globalVersion = globalVersion - 1;
1876
+ // for backwards compat
1877
+ this.effect = this;
1878
+ this.__v_isReadonly = !setter;
1879
+ this.isSSR = isSSR;
1880
+ }
1881
+ /**
1882
+ * @internal
1883
+ */
1884
+ notify() {
1885
+ if (activeSub !== this) {
1886
+ this.flags |= 16;
1887
+ this.dep.notify();
1888
+ }
1889
+ }
1890
+ get value() {
1891
+ const link = this.dep.track({
1892
+ target: this,
1893
+ type: "get",
1894
+ key: "value"
1895
+ }) ;
1896
+ refreshComputed(this);
1897
+ if (link) {
1898
+ link.version = this.dep.version;
1899
+ }
1900
+ return this._value;
1901
+ }
1902
+ set value(newValue) {
1903
+ if (this.setter) {
1904
+ this.setter(newValue);
1905
+ } else {
1906
+ warn$2("Write operation failed: computed value is readonly");
1907
+ }
1908
+ }
1909
+ }
1910
+ function computed$1(getterOrOptions, debugOptions, isSSR = false) {
1911
+ let getter;
1912
+ let setter;
1913
+ if (isFunction(getterOrOptions)) {
1914
+ getter = getterOrOptions;
1915
+ } else {
1916
+ getter = getterOrOptions.get;
1917
+ setter = getterOrOptions.set;
1918
+ }
1919
+ const cRef = new ComputedRefImpl(getter, setter, isSSR);
1920
+ if (debugOptions && !isSSR) {
1921
+ cRef.onTrack = debugOptions.onTrack;
1922
+ cRef.onTrigger = debugOptions.onTrigger;
1923
+ }
1924
+ return cRef;
1925
+ }
1926
+
1572
1927
  const TrackOpTypes = {
1573
1928
  "GET": "get",
1574
1929
  "HAS": "has",
@@ -1728,7 +2083,9 @@ const ErrorCodes = {
1728
2083
  "ASYNC_COMPONENT_LOADER": 13,
1729
2084
  "13": "ASYNC_COMPONENT_LOADER",
1730
2085
  "SCHEDULER": 14,
1731
- "14": "SCHEDULER"
2086
+ "14": "SCHEDULER",
2087
+ "APP_UNMOUNT_CLEANUP": 15,
2088
+ "15": "APP_UNMOUNT_CLEANUP"
1732
2089
  };
1733
2090
  const ErrorTypeStrings$1 = {
1734
2091
  ["sp"]: "serverPrefetch hook",
@@ -1759,7 +2116,8 @@ const ErrorTypeStrings$1 = {
1759
2116
  [11]: "app warnHandler",
1760
2117
  [12]: "ref function",
1761
2118
  [13]: "async component loader",
1762
- [14]: "scheduler flush. This is likely a Vue internals bug. Please open an issue at https://github.com/vuejs/core ."
2119
+ [14]: "scheduler flush. This is likely a Vue internals bug. Please open an issue at https://github.com/vuejs/core .",
2120
+ [15]: "app unmount cleanup function"
1763
2121
  };
1764
2122
  function callWithErrorHandling(fn, instance, type, args) {
1765
2123
  try {
@@ -1861,7 +2219,7 @@ function findInsertionIndex(id) {
1861
2219
  const middle = start + end >>> 1;
1862
2220
  const middleJob = queue[middle];
1863
2221
  const middleJobId = getId(middleJob);
1864
- if (middleJobId < id || middleJobId === id && middleJob.pre) {
2222
+ if (middleJobId < id || middleJobId === id && middleJob.flags & 2) {
1865
2223
  start = middle + 1;
1866
2224
  } else {
1867
2225
  end = middle;
@@ -1870,15 +2228,21 @@ function findInsertionIndex(id) {
1870
2228
  return start;
1871
2229
  }
1872
2230
  function queueJob(job) {
1873
- if (!queue.length || !queue.includes(
1874
- job,
1875
- isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex
1876
- )) {
2231
+ var _a;
2232
+ if (!(job.flags & 1)) {
1877
2233
  if (job.id == null) {
1878
2234
  queue.push(job);
2235
+ } else if (
2236
+ // fast path when the job id is larger than the tail
2237
+ !(job.flags & 2) && job.id >= (((_a = queue[queue.length - 1]) == null ? void 0 : _a.id) || 0)
2238
+ ) {
2239
+ queue.push(job);
1879
2240
  } else {
1880
2241
  queue.splice(findInsertionIndex(job.id), 0, job);
1881
2242
  }
2243
+ if (!(job.flags & 4)) {
2244
+ job.flags |= 1;
2245
+ }
1882
2246
  queueFlush();
1883
2247
  }
1884
2248
  }
@@ -1896,11 +2260,11 @@ function invalidateJob(job) {
1896
2260
  }
1897
2261
  function queuePostFlushCb(cb) {
1898
2262
  if (!isArray(cb)) {
1899
- if (!activePostFlushCbs || !activePostFlushCbs.includes(
1900
- cb,
1901
- cb.allowRecurse ? postFlushIndex + 1 : postFlushIndex
1902
- )) {
2263
+ if (!(cb.flags & 1)) {
1903
2264
  pendingPostFlushCbs.push(cb);
2265
+ if (!(cb.flags & 4)) {
2266
+ cb.flags |= 1;
2267
+ }
1904
2268
  }
1905
2269
  } else {
1906
2270
  pendingPostFlushCbs.push(...cb);
@@ -1913,7 +2277,7 @@ function flushPreFlushCbs(instance, seen, i = isFlushing ? flushIndex + 1 : 0) {
1913
2277
  }
1914
2278
  for (; i < queue.length; i++) {
1915
2279
  const cb = queue[i];
1916
- if (cb && cb.pre) {
2280
+ if (cb && cb.flags & 2) {
1917
2281
  if (instance && cb.id !== instance.uid) {
1918
2282
  continue;
1919
2283
  }
@@ -1923,6 +2287,7 @@ function flushPreFlushCbs(instance, seen, i = isFlushing ? flushIndex + 1 : 0) {
1923
2287
  queue.splice(i, 1);
1924
2288
  i--;
1925
2289
  cb();
2290
+ cb.flags &= ~1;
1926
2291
  }
1927
2292
  }
1928
2293
  }
@@ -1945,6 +2310,7 @@ function flushPostFlushCbs(seen) {
1945
2310
  continue;
1946
2311
  }
1947
2312
  activePostFlushCbs[postFlushIndex]();
2313
+ activePostFlushCbs[postFlushIndex].flags &= ~1;
1948
2314
  }
1949
2315
  activePostFlushCbs = null;
1950
2316
  postFlushIndex = 0;
@@ -1954,9 +2320,11 @@ const getId = (job) => job.id == null ? Infinity : job.id;
1954
2320
  const comparator = (a, b) => {
1955
2321
  const diff = getId(a) - getId(b);
1956
2322
  if (diff === 0) {
1957
- if (a.pre && !b.pre)
2323
+ const isAPre = a.flags & 2;
2324
+ const isBPre = b.flags & 2;
2325
+ if (isAPre && !isBPre)
1958
2326
  return -1;
1959
- if (b.pre && !a.pre)
2327
+ if (isBPre && !isAPre)
1960
2328
  return 1;
1961
2329
  }
1962
2330
  return diff;
@@ -1972,11 +2340,12 @@ function flushJobs(seen) {
1972
2340
  try {
1973
2341
  for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
1974
2342
  const job = queue[flushIndex];
1975
- if (job && job.active !== false) {
2343
+ if (job && !(job.flags & 8)) {
1976
2344
  if (check(job)) {
1977
2345
  continue;
1978
2346
  }
1979
2347
  callWithErrorHandling(job, null, 14);
2348
+ job.flags &= ~1;
1980
2349
  }
1981
2350
  }
1982
2351
  } finally {
@@ -2058,7 +2427,6 @@ function rerender(id, newRender) {
2058
2427
  }
2059
2428
  instance.renderCache = [];
2060
2429
  isHmrUpdating = true;
2061
- instance.effect.dirty = true;
2062
2430
  instance.update();
2063
2431
  isHmrUpdating = false;
2064
2432
  });
@@ -2086,7 +2454,6 @@ function reload(id, newComp) {
2086
2454
  instance.ceReload(newComp.styles);
2087
2455
  hmrDirtyComponents.delete(oldComp);
2088
2456
  } else if (instance.parent) {
2089
- instance.parent.effect.dirty = true;
2090
2457
  queueJob(instance.parent.update);
2091
2458
  } else if (instance.appContext.reload) {
2092
2459
  instance.appContext.reload();
@@ -3492,8 +3859,8 @@ function doWatch(source, cb, {
3492
3859
  };
3493
3860
  };
3494
3861
  let oldValue = isMultiSource ? new Array(source.length).fill(INITIAL_WATCHER_VALUE) : INITIAL_WATCHER_VALUE;
3495
- const job = () => {
3496
- if (!effect.active || !effect.dirty) {
3862
+ const job = (immediateFirstRun) => {
3863
+ if (!(effect.flags & 1) || !effect.dirty && !immediateFirstRun) {
3497
3864
  return;
3498
3865
  }
3499
3866
  if (cb) {
@@ -3514,19 +3881,22 @@ function doWatch(source, cb, {
3514
3881
  effect.run();
3515
3882
  }
3516
3883
  };
3517
- job.allowRecurse = !!cb;
3884
+ if (cb)
3885
+ job.flags |= 4;
3886
+ const effect = new ReactiveEffect(getter);
3518
3887
  let scheduler;
3519
3888
  if (flush === "sync") {
3889
+ effect.flags |= 64;
3520
3890
  scheduler = job;
3521
3891
  } else if (flush === "post") {
3522
3892
  scheduler = () => queuePostRenderEffect(job, instance && instance.suspense);
3523
3893
  } else {
3524
- job.pre = true;
3894
+ job.flags |= 2;
3525
3895
  if (instance)
3526
3896
  job.id = instance.uid;
3527
3897
  scheduler = () => queueJob(job);
3528
3898
  }
3529
- const effect = new ReactiveEffect(getter, NOOP, scheduler);
3899
+ effect.scheduler = scheduler;
3530
3900
  const scope = getCurrentScope();
3531
3901
  const unwatch = () => {
3532
3902
  effect.stop();
@@ -3540,7 +3910,7 @@ function doWatch(source, cb, {
3540
3910
  }
3541
3911
  if (cb) {
3542
3912
  if (immediate) {
3543
- job();
3913
+ job(true);
3544
3914
  } else {
3545
3915
  oldValue = effect.run();
3546
3916
  }
@@ -3714,22 +4084,7 @@ const BaseTransitionImpl = {
3714
4084
  if (!children || !children.length) {
3715
4085
  return;
3716
4086
  }
3717
- let child = children[0];
3718
- if (children.length > 1) {
3719
- let hasFound = false;
3720
- for (const c of children) {
3721
- if (c.type !== Comment) {
3722
- if (hasFound) {
3723
- warn$1(
3724
- "<transition> can only be used on a single element or component. Use <transition-group> for lists."
3725
- );
3726
- break;
3727
- }
3728
- child = c;
3729
- hasFound = true;
3730
- }
3731
- }
3732
- }
4087
+ const child = findNonCommentChild(children);
3733
4088
  const rawProps = toRaw(props);
3734
4089
  const { mode } = rawProps;
3735
4090
  if (mode && mode !== "in-out" && mode !== "out-in" && mode !== "default") {
@@ -3738,7 +4093,7 @@ const BaseTransitionImpl = {
3738
4093
  if (state.isLeaving) {
3739
4094
  return emptyPlaceholder(child);
3740
4095
  }
3741
- const innerChild = getKeepAliveChild(child);
4096
+ const innerChild = getInnerChild$1(child);
3742
4097
  if (!innerChild) {
3743
4098
  return emptyPlaceholder(child);
3744
4099
  }
@@ -3750,7 +4105,7 @@ const BaseTransitionImpl = {
3750
4105
  );
3751
4106
  setTransitionHooks(innerChild, enterHooks);
3752
4107
  const oldChild = instance.subTree;
3753
- const oldInnerChild = oldChild && getKeepAliveChild(oldChild);
4108
+ const oldInnerChild = oldChild && getInnerChild$1(oldChild);
3754
4109
  if (oldInnerChild && oldInnerChild.type !== Comment && !isSameVNodeType(innerChild, oldInnerChild)) {
3755
4110
  const leavingHooks = resolveTransitionHooks(
3756
4111
  oldInnerChild,
@@ -3763,8 +4118,7 @@ const BaseTransitionImpl = {
3763
4118
  state.isLeaving = true;
3764
4119
  leavingHooks.afterLeave = () => {
3765
4120
  state.isLeaving = false;
3766
- if (instance.update.active !== false) {
3767
- instance.effect.dirty = true;
4121
+ if (!(instance.job.flags & 8)) {
3768
4122
  instance.update();
3769
4123
  }
3770
4124
  };
@@ -3789,6 +4143,25 @@ const BaseTransitionImpl = {
3789
4143
  };
3790
4144
  }
3791
4145
  };
4146
+ function findNonCommentChild(children) {
4147
+ let child = children[0];
4148
+ if (children.length > 1) {
4149
+ let hasFound = false;
4150
+ for (const c of children) {
4151
+ if (c.type !== Comment) {
4152
+ if (hasFound) {
4153
+ warn$1(
4154
+ "<transition> can only be used on a single element or component. Use <transition-group> for lists."
4155
+ );
4156
+ break;
4157
+ }
4158
+ child = c;
4159
+ hasFound = true;
4160
+ }
4161
+ }
4162
+ }
4163
+ return child;
4164
+ }
3792
4165
  const BaseTransition = BaseTransitionImpl;
3793
4166
  function getLeavingNodesForType(state, vnode) {
3794
4167
  const { leavingVNodes } = state;
@@ -3943,8 +4316,11 @@ function emptyPlaceholder(vnode) {
3943
4316
  return vnode;
3944
4317
  }
3945
4318
  }
3946
- function getKeepAliveChild(vnode) {
4319
+ function getInnerChild$1(vnode) {
3947
4320
  if (!isKeepAlive(vnode)) {
4321
+ if (isTeleport(vnode.type) && vnode.children) {
4322
+ return findNonCommentChild(vnode.children);
4323
+ }
3948
4324
  return vnode;
3949
4325
  }
3950
4326
  if (vnode.component) {
@@ -4113,7 +4489,6 @@ function defineAsyncComponent(source) {
4113
4489
  load().then(() => {
4114
4490
  loaded.value = true;
4115
4491
  if (instance.parent && isKeepAlive(instance.parent.vnode)) {
4116
- instance.parent.effect.dirty = true;
4117
4492
  queueJob(instance.parent.update);
4118
4493
  }
4119
4494
  }).catch((err) => {
@@ -4438,10 +4813,20 @@ function onErrorCaptured(hook, target = currentInstance) {
4438
4813
  function renderList(source, renderItem, cache, index) {
4439
4814
  let ret;
4440
4815
  const cached = cache && cache[index];
4441
- if (isArray(source) || isString(source)) {
4816
+ const sourceIsArray = isArray(source);
4817
+ const sourceIsReactiveArray = sourceIsArray && isReactive(source);
4818
+ if (sourceIsArray || isString(source)) {
4819
+ if (sourceIsReactiveArray) {
4820
+ source = shallowReadArray(source);
4821
+ }
4442
4822
  ret = new Array(source.length);
4443
4823
  for (let i = 0, l = source.length; i < l; i++) {
4444
- ret[i] = renderItem(source[i], i, void 0, cached && cached[i]);
4824
+ ret[i] = renderItem(
4825
+ sourceIsReactiveArray ? toReactive(source[i]) : source[i],
4826
+ i,
4827
+ void 0,
4828
+ cached && cached[i]
4829
+ );
4445
4830
  }
4446
4831
  } else if (typeof source === "number") {
4447
4832
  if (!Number.isInteger(source)) {
@@ -4576,7 +4961,6 @@ const publicPropertiesMap = (
4576
4961
  $emit: (i) => i.emit,
4577
4962
  $options: (i) => resolveMergedOptions(i) ,
4578
4963
  $forceUpdate: (i) => i.f || (i.f = () => {
4579
- i.effect.dirty = true;
4580
4964
  queueJob(i.update);
4581
4965
  }),
4582
4966
  $nextTick: (i) => i.n || (i.n = nextTick.bind(i.proxy)),
@@ -5371,6 +5755,7 @@ function createAppAPI(render, hydrate) {
5371
5755
  }
5372
5756
  const context = createAppContext();
5373
5757
  const installedPlugins = /* @__PURE__ */ new WeakSet();
5758
+ const pluginCleanupFns = [];
5374
5759
  let isMounted = false;
5375
5760
  const app = context.app = {
5376
5761
  _uid: uid$1++,
@@ -5488,8 +5873,21 @@ If you want to remount the same app, move your app creation logic into a factory
5488
5873
  );
5489
5874
  }
5490
5875
  },
5876
+ onUnmount(cleanupFn) {
5877
+ if (typeof cleanupFn !== "function") {
5878
+ warn$1(
5879
+ `Expected function as first argument to app.onUnmount(), but got ${typeof cleanupFn}`
5880
+ );
5881
+ }
5882
+ pluginCleanupFns.push(cleanupFn);
5883
+ },
5491
5884
  unmount() {
5492
5885
  if (isMounted) {
5886
+ callWithAsyncErrorHandling(
5887
+ pluginCleanupFns,
5888
+ app._instance,
5889
+ 15
5890
+ );
5493
5891
  render(null, app._container);
5494
5892
  {
5495
5893
  app._instance = null;
@@ -5909,7 +6307,9 @@ const isSimpleType = /* @__PURE__ */ makeMap(
5909
6307
  function assertType(value, type) {
5910
6308
  let valid;
5911
6309
  const expectedType = getType(type);
5912
- if (isSimpleType(expectedType)) {
6310
+ if (expectedType === "null") {
6311
+ valid = value === null;
6312
+ } else if (isSimpleType(expectedType)) {
5913
6313
  const t = typeof value;
5914
6314
  valid = t === expectedType.toLowerCase();
5915
6315
  if (!valid && t === "object") {
@@ -5919,8 +6319,6 @@ function assertType(value, type) {
5919
6319
  valid = isObject(value);
5920
6320
  } else if (expectedType === "Array") {
5921
6321
  valid = isArray(value);
5922
- } else if (expectedType === "null") {
5923
- valid = value === null;
5924
6322
  } else {
5925
6323
  valid = value instanceof type;
5926
6324
  }
@@ -7444,7 +7842,6 @@ function baseCreateRenderer(options, createHydrationFns) {
7444
7842
  } else {
7445
7843
  instance.next = n2;
7446
7844
  invalidateJob(instance.update);
7447
- instance.effect.dirty = true;
7448
7845
  instance.update();
7449
7846
  }
7450
7847
  } else {
@@ -7627,24 +8024,18 @@ function baseCreateRenderer(options, createHydrationFns) {
7627
8024
  }
7628
8025
  }
7629
8026
  };
7630
- const effect = instance.effect = new ReactiveEffect(
7631
- componentUpdateFn,
7632
- NOOP,
7633
- () => queueJob(update),
7634
- instance.scope
7635
- // track it in component's effect scope
7636
- );
7637
- const update = instance.update = () => {
7638
- if (effect.dirty) {
7639
- effect.run();
7640
- }
7641
- };
7642
- update.id = instance.uid;
8027
+ instance.scope.on();
8028
+ const effect = instance.effect = new ReactiveEffect(componentUpdateFn);
8029
+ instance.scope.off();
8030
+ const update = instance.update = effect.run.bind(effect);
8031
+ const job = instance.job = effect.runIfDirty.bind(effect);
8032
+ job.id = instance.uid;
8033
+ effect.scheduler = () => queueJob(job);
7643
8034
  toggleRecurse(instance, true);
7644
8035
  {
7645
8036
  effect.onTrack = instance.rtc ? (e) => invokeArrayFns(instance.rtc, e) : void 0;
7646
8037
  effect.onTrigger = instance.rtg ? (e) => invokeArrayFns(instance.rtg, e) : void 0;
7647
- update.ownerInstance = instance;
8038
+ job.ownerInstance = instance;
7648
8039
  }
7649
8040
  update();
7650
8041
  };
@@ -8111,13 +8502,13 @@ function baseCreateRenderer(options, createHydrationFns) {
8111
8502
  if (instance.type.__hmrId) {
8112
8503
  unregisterHMR(instance);
8113
8504
  }
8114
- const { bum, scope, update, subTree, um } = instance;
8505
+ const { bum, scope, job, subTree, um } = instance;
8115
8506
  if (bum) {
8116
8507
  invokeArrayFns(bum);
8117
8508
  }
8118
8509
  scope.stop();
8119
- if (update) {
8120
- update.active = false;
8510
+ if (job) {
8511
+ job.flags |= 8;
8121
8512
  unmount(subTree, instance, parentSuspense, doRemove);
8122
8513
  }
8123
8514
  if (um) {
@@ -8203,8 +8594,14 @@ function baseCreateRenderer(options, createHydrationFns) {
8203
8594
  function resolveChildrenNamespace({ type, props }, currentNamespace) {
8204
8595
  return currentNamespace === "svg" && type === "foreignObject" || currentNamespace === "mathml" && type === "annotation-xml" && props && props.encoding && props.encoding.includes("html") ? void 0 : currentNamespace;
8205
8596
  }
8206
- function toggleRecurse({ effect, update }, allowed) {
8207
- effect.allowRecurse = update.allowRecurse = allowed;
8597
+ function toggleRecurse({ effect, job }, allowed) {
8598
+ if (allowed) {
8599
+ effect.flags |= 32;
8600
+ job.flags |= 4;
8601
+ } else {
8602
+ effect.flags &= ~32;
8603
+ job.flags &= ~4;
8604
+ }
8208
8605
  }
8209
8606
  function needTransition(parentSuspense, transition) {
8210
8607
  return (!parentSuspense || parentSuspense && !parentSuspense.pendingBranch) && transition && !transition.persisted;
@@ -8944,6 +9341,7 @@ function createComponentInstance(vnode, parent, suspense) {
8944
9341
  effect: null,
8945
9342
  update: null,
8946
9343
  // will be set synchronously right after creation
9344
+ job: null,
8947
9345
  scope: new EffectScope(
8948
9346
  true
8949
9347
  /* detached */
@@ -9437,7 +9835,8 @@ function initCustomFormatter() {
9437
9835
  {},
9438
9836
  ["span", vueStyle, genRefFlag(obj)],
9439
9837
  "<",
9440
- formatValue(obj.value),
9838
+ // avoid debugger accessing value affecting behavior
9839
+ formatValue("_value" in obj ? obj._value : obj),
9441
9840
  `>`
9442
9841
  ];
9443
9842
  } else if (isReactive(obj)) {
@@ -9617,7 +10016,7 @@ function isMemoSame(cached, memo) {
9617
10016
  return true;
9618
10017
  }
9619
10018
 
9620
- const version = "3.4.26";
10019
+ const version = "3.5.0-alpha.2";
9621
10020
  const warn = warn$1 ;
9622
10021
  const ErrorTypeStrings = ErrorTypeStrings$1 ;
9623
10022
  const devtools = devtools$1 ;
@@ -11072,7 +11471,9 @@ const withKeys = (fn, modifiers) => {
11072
11471
  return;
11073
11472
  }
11074
11473
  const eventKey = hyphenate(event.key);
11075
- if (modifiers.some((k) => k === eventKey || keyNames[k] === eventKey)) {
11474
+ if (modifiers.some(
11475
+ (k) => k === eventKey || keyNames[k] === eventKey
11476
+ )) {
11076
11477
  return fn(event);
11077
11478
  }
11078
11479
  });
@@ -16639,9 +17040,183 @@ const ignoreSideEffectTags = (node, context) => {
16639
17040
  }
16640
17041
  };
16641
17042
 
17043
+ function isValidHTMLNesting(parent, child) {
17044
+ if (parent in onlyValidChildren) {
17045
+ return onlyValidChildren[parent].has(child);
17046
+ }
17047
+ if (child in onlyValidParents) {
17048
+ return onlyValidParents[child].has(parent);
17049
+ }
17050
+ if (parent in knownInvalidChildren) {
17051
+ if (knownInvalidChildren[parent].has(child))
17052
+ return false;
17053
+ }
17054
+ if (child in knownInvalidParents) {
17055
+ if (knownInvalidParents[child].has(parent))
17056
+ return false;
17057
+ }
17058
+ return true;
17059
+ }
17060
+ const headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
17061
+ const emptySet = /* @__PURE__ */ new Set([]);
17062
+ const onlyValidChildren = {
17063
+ head: /* @__PURE__ */ new Set([
17064
+ "base",
17065
+ "basefront",
17066
+ "bgsound",
17067
+ "link",
17068
+ "meta",
17069
+ "title",
17070
+ "noscript",
17071
+ "noframes",
17072
+ "style",
17073
+ "script",
17074
+ "template"
17075
+ ]),
17076
+ optgroup: /* @__PURE__ */ new Set(["option"]),
17077
+ select: /* @__PURE__ */ new Set(["optgroup", "option", "hr"]),
17078
+ // table
17079
+ table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
17080
+ tr: /* @__PURE__ */ new Set(["td", "th"]),
17081
+ colgroup: /* @__PURE__ */ new Set(["col"]),
17082
+ tbody: /* @__PURE__ */ new Set(["tr"]),
17083
+ thead: /* @__PURE__ */ new Set(["tr"]),
17084
+ tfoot: /* @__PURE__ */ new Set(["tr"]),
17085
+ // these elements can not have any children elements
17086
+ script: emptySet,
17087
+ iframe: emptySet,
17088
+ option: emptySet,
17089
+ textarea: emptySet,
17090
+ style: emptySet,
17091
+ title: emptySet
17092
+ };
17093
+ const onlyValidParents = {
17094
+ // sections
17095
+ html: emptySet,
17096
+ body: /* @__PURE__ */ new Set(["html"]),
17097
+ head: /* @__PURE__ */ new Set(["html"]),
17098
+ // table
17099
+ td: /* @__PURE__ */ new Set(["tr"]),
17100
+ colgroup: /* @__PURE__ */ new Set(["table"]),
17101
+ caption: /* @__PURE__ */ new Set(["table"]),
17102
+ tbody: /* @__PURE__ */ new Set(["table"]),
17103
+ tfoot: /* @__PURE__ */ new Set(["table"]),
17104
+ col: /* @__PURE__ */ new Set(["colgroup"]),
17105
+ th: /* @__PURE__ */ new Set(["tr"]),
17106
+ thead: /* @__PURE__ */ new Set(["table"]),
17107
+ tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
17108
+ // data list
17109
+ dd: /* @__PURE__ */ new Set(["dl", "div"]),
17110
+ dt: /* @__PURE__ */ new Set(["dl", "div"]),
17111
+ // other
17112
+ figcaption: /* @__PURE__ */ new Set(["figure"]),
17113
+ // li: new Set(["ul", "ol"]),
17114
+ summary: /* @__PURE__ */ new Set(["details"]),
17115
+ area: /* @__PURE__ */ new Set(["map"])
17116
+ };
17117
+ const knownInvalidChildren = {
17118
+ p: /* @__PURE__ */ new Set([
17119
+ "address",
17120
+ "article",
17121
+ "aside",
17122
+ "blockquote",
17123
+ "center",
17124
+ "details",
17125
+ "dialog",
17126
+ "dir",
17127
+ "div",
17128
+ "dl",
17129
+ "fieldset",
17130
+ "figure",
17131
+ "footer",
17132
+ "form",
17133
+ "h1",
17134
+ "h2",
17135
+ "h3",
17136
+ "h4",
17137
+ "h5",
17138
+ "h6",
17139
+ "header",
17140
+ "hgroup",
17141
+ "hr",
17142
+ "li",
17143
+ "main",
17144
+ "nav",
17145
+ "menu",
17146
+ "ol",
17147
+ "p",
17148
+ "pre",
17149
+ "section",
17150
+ "table",
17151
+ "ul"
17152
+ ]),
17153
+ svg: /* @__PURE__ */ new Set([
17154
+ "b",
17155
+ "blockquote",
17156
+ "br",
17157
+ "code",
17158
+ "dd",
17159
+ "div",
17160
+ "dl",
17161
+ "dt",
17162
+ "em",
17163
+ "embed",
17164
+ "h1",
17165
+ "h2",
17166
+ "h3",
17167
+ "h4",
17168
+ "h5",
17169
+ "h6",
17170
+ "hr",
17171
+ "i",
17172
+ "img",
17173
+ "li",
17174
+ "menu",
17175
+ "meta",
17176
+ "ol",
17177
+ "p",
17178
+ "pre",
17179
+ "ruby",
17180
+ "s",
17181
+ "small",
17182
+ "span",
17183
+ "strong",
17184
+ "sub",
17185
+ "sup",
17186
+ "table",
17187
+ "u",
17188
+ "ul",
17189
+ "var"
17190
+ ])
17191
+ };
17192
+ const knownInvalidParents = {
17193
+ a: /* @__PURE__ */ new Set(["a"]),
17194
+ button: /* @__PURE__ */ new Set(["button"]),
17195
+ dd: /* @__PURE__ */ new Set(["dd", "dt"]),
17196
+ dt: /* @__PURE__ */ new Set(["dd", "dt"]),
17197
+ form: /* @__PURE__ */ new Set(["form"]),
17198
+ li: /* @__PURE__ */ new Set(["li"]),
17199
+ h1: headings,
17200
+ h2: headings,
17201
+ h3: headings,
17202
+ h4: headings,
17203
+ h5: headings,
17204
+ h6: headings
17205
+ };
17206
+
17207
+ const validateHtmlNesting = (node, context) => {
17208
+ if (node.type === 1 && node.tagType === 0 && context.parent && context.parent.type === 1 && context.parent.tagType === 0 && !isValidHTMLNesting(context.parent.tag, node.tag)) {
17209
+ const error = new SyntaxError(
17210
+ `<${node.tag}> cannot be child of <${context.parent.tag}>, according to HTML specifications. This can cause hydration errors or potentially disrupt future functionality.`
17211
+ );
17212
+ error.loc = node.loc;
17213
+ context.onWarn(error);
17214
+ }
17215
+ };
17216
+
16642
17217
  const DOMNodeTransforms = [
16643
17218
  transformStyle,
16644
- ...[transformTransition]
17219
+ ...[transformTransition, validateHtmlNesting]
16645
17220
  ];
16646
17221
  const DOMDirectiveTransforms = {
16647
17222
  cloak: noopDirectiveTransform,