@unsetsoft/ryunixjs 1.2.4-canary.14 → 1.2.4-canary.16

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.
@@ -557,9 +557,19 @@ const clearContainer = (container) => {
557
557
  const commitRoot = () => {
558
558
  const state = getState();
559
559
  state.deletions.forEach(commitWork);
560
- commitWork(state.wipRoot.child);
561
- state.currentRoot = state.wipRoot;
562
- state.wipRoot = null;
560
+
561
+ const finishedWork = state.wipRoot;
562
+
563
+ // Swap the currentRoot pointer BEFORE running effects
564
+ // This allows dispatches inside effects to base their new work on the just-finished tree
565
+ state.currentRoot = finishedWork;
566
+
567
+ commitWork(finishedWork.child);
568
+
569
+ // If wipRoot was not reassigned by a synchronous dispatch during effects, clear it
570
+ if (state.wipRoot === finishedWork) {
571
+ state.wipRoot = null;
572
+ }
563
573
  };
564
574
 
565
575
  const commitWork = (fiber) => {
@@ -592,7 +602,7 @@ const commitWork = (fiber) => {
592
602
  runEffects(fiber);
593
603
  } else if (fiber.effectTag === EFFECT_TAGS.DELETION) {
594
604
  cancelEffectsDeep(fiber);
595
- commitDeletion(fiber, domParent);
605
+ commitDeletion(fiber);
596
606
  return
597
607
  }
598
608
 
@@ -602,11 +612,13 @@ const commitWork = (fiber) => {
602
612
 
603
613
  const commitDeletion = (fiber, domParent) => {
604
614
  if (fiber.dom) {
605
- domParent.removeChild(fiber.dom);
615
+ if (fiber.dom.parentNode) {
616
+ fiber.dom.parentNode.removeChild(fiber.dom);
617
+ }
606
618
  } else {
607
619
  let child = fiber.child;
608
620
  while (child) {
609
- commitDeletion(child, domParent);
621
+ commitDeletion(child);
610
622
  child = child.sibling;
611
623
  }
612
624
  }
@@ -619,6 +631,7 @@ const reconcileChildren = (wipFiber, elements) => {
619
631
  const state = getState();
620
632
  let index = 0;
621
633
  let prevSibling;
634
+ let isFirstChild = true;
622
635
 
623
636
  // Build map of old fibers by key/index
624
637
  const oldFiberMap = new Map();
@@ -626,7 +639,7 @@ const reconcileChildren = (wipFiber, elements) => {
626
639
  let position = 0;
627
640
 
628
641
  while (oldFiber) {
629
- const key = oldFiber.key ?? `__index_${position}__`;
642
+ const key = oldFiber.key ?? `__index_${oldFiber.index ?? position}__`;
630
643
  oldFiberMap.set(key, oldFiber);
631
644
  oldFiber = oldFiber.sibling;
632
645
  position++;
@@ -657,6 +670,7 @@ const reconcileChildren = (wipFiber, elements) => {
657
670
  effectTag: EFFECT_TAGS.UPDATE,
658
671
  hooks: matchedFiber.hooks,
659
672
  key: element.key,
673
+ index,
660
674
  };
661
675
  oldFiberMap.delete(key);
662
676
  } else {
@@ -669,6 +683,7 @@ const reconcileChildren = (wipFiber, elements) => {
669
683
  alternate: null,
670
684
  effectTag: EFFECT_TAGS.PLACEMENT,
671
685
  key: element.key,
686
+ index,
672
687
  };
673
688
 
674
689
  // Mark matched fiber for deletion if exists
@@ -680,8 +695,9 @@ const reconcileChildren = (wipFiber, elements) => {
680
695
  }
681
696
 
682
697
  // Link fibers
683
- if (index === 0) {
698
+ if (isFirstChild) {
684
699
  wipFiber.child = newFiber;
700
+ isFirstChild = false;
685
701
  } else if (newFiber) {
686
702
  prevSibling.sibling = newFiber;
687
703
  }
@@ -803,14 +819,14 @@ const useReducer = (reducer, initialState, init) => {
803
819
  hook.queue.push(action);
804
820
 
805
821
  const currentState = getState();
806
- currentState.wipRoot = currentState.currentRoot ? {
807
- dom: currentState.currentRoot.dom,
808
- props: currentState.currentRoot.props,
809
- alternate: currentState.currentRoot,
810
- } : {
811
- dom: currentState.wipRoot ? currentState.wipRoot.dom : currentState.containerRoot,
812
- props: currentState.wipRoot ? currentState.wipRoot.props : { children: [] },
813
- alternate: null,
822
+ const activeRoot = currentState.currentRoot || currentState.wipRoot;
823
+
824
+ if (!activeRoot) return
825
+
826
+ currentState.wipRoot = {
827
+ dom: activeRoot.dom,
828
+ props: activeRoot.props,
829
+ alternate: currentState.currentRoot || null,
814
830
  };
815
831
  currentState.deletions = [];
816
832
  currentState.hookIndex = 0;