Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
atellmer committed Nov 14, 2022
1 parent fd98ac1 commit 6e1bb0f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/core/src/fiber/fiber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Fiber<N = NativeElement> {
public hook: Hook;
public shadow: Fiber<N>;
public provider: Map<Context, ContextProviderValue>;
public transposition: boolean;
public mountedToHost: boolean;
public portalHost: boolean;
public effectHost: boolean;
Expand All @@ -57,6 +58,7 @@ class Fiber<N = NativeElement> {
this.hook = options.hook || createHook();
this.shadow = options.shadow || null;
this.provider = options.provider || null;
this.transposition = !detectIsUndefined(options.transposition) ? options.transposition : false;
this.mountedToHost = !detectIsUndefined(options.mountedToHost) || false;
this.portalHost = !detectIsUndefined(options.portalHost) ? options.portalHost : false;
this.effectHost = !detectIsUndefined(options.effectHost) ? options.effectHost : false;
Expand Down Expand Up @@ -599,6 +601,7 @@ function getRootShadow(options: GetRootShadowOptions) {
if (shadow) {
fiber.hook = shadow.hook;
fiber.provider = shadow.provider;
alternate.transposition = true;
}
}

Expand Down Expand Up @@ -808,7 +811,9 @@ function commitChanges() {
if (fiber.effectHost) {
walkFiber({
fiber,
onLoop: ({ nextFiber, isReturn }) => {
onLoop: ({ nextFiber, isReturn, stop }) => {
if (nextFiber === fiber.nextSibling || fiber.transposition) return stop();

if (!isReturn && detectIsComponentFactory(nextFiber.instance)) {
cleanupEffects(nextFiber.hook);
}
Expand Down Expand Up @@ -873,13 +878,15 @@ type OnLoopOptions<T> = {
nextFiber: Fiber<T>;
isReturn: boolean;
resetIsDeepWalking: () => void;
stop: () => void;
};

function walkFiber<T = unknown>(options: WalkFiberOptions<T>) {
const { fiber, onLoop } = options;
let nextFiber = fiber;
let isDeepWalking = true;
let isReturn = false;
let isStopped = false;
const visitedMap = new Map<Fiber, true>();
const detectCanVisit = (fiber: Fiber) => !visitedMap.get(fiber);

Expand All @@ -888,8 +895,13 @@ function walkFiber<T = unknown>(options: WalkFiberOptions<T>) {
nextFiber: nextFiber as Fiber<T>,
isReturn,
resetIsDeepWalking: () => (isDeepWalking = false),
stop: () => (isStopped = true),
});

if (isStopped) {
break;
}

if (nextFiber.child && isDeepWalking && detectCanVisit(nextFiber.child)) {
const newFiber = nextFiber.child;

Expand Down

0 comments on commit 6e1bb0f

Please sign in to comment.