Skip to content

Commit 7313f32

Browse files
rtvinerNkmailind-taniacaitlinchan23
committed
check if fromLinkFiber class already exists, remove if it does, add new class, changed add id to add class
Co-authored-by: Nkmai <[email protected]> Co-authored-by: lind-tania <[email protected]> Co-authored-by: rtviner <[email protected]> Co-authored-by: caitlinchan23 <[email protected]>
1 parent abd53bc commit 7313f32

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/backend/linkFiber.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ function createTree(
356356
isRecoil === false
357357
) {
358358
if (memoizedState.queue) {
359-
console.log("line 357...")
360359
// Hooks states are stored as a linked list using memoizedState.next,
361360
// so we must traverse through the list and get the states.
362361
// We then store them along with the corresponding memoizedState.queue,
@@ -411,17 +410,37 @@ function createTree(
411410

412411
while (pointer !== null) {
413412
if(pointer.stateNode !== null){
414-
rtid = "fromLinkFiber" + rtidCounter++
415-
recoilDomNode[currentFiber.elementType.name].push(rtid)
416-
pointer.stateNode.setAttribute("id", rtid)
413+
rtid = "fromLinkFiber" + rtidCounter++;
414+
recoilDomNode[currentFiber.elementType.name].push(rtid)
415+
// check if rtid is already present
416+
// remove existing rtid before adding a new one
417+
if (pointer.stateNode.classList.length > 0) {
418+
let lastClass = pointer.stateNode.classList[pointer.stateNode.classList.length -1];
419+
console.log("last class: ", lastClass, "linkFiber class? ", lastClass.includes("fromLinkFiber"));
420+
if (lastClass.includes("fromLinkFiber")) {
421+
pointer.stateNode.classList.remove(lastClass);
422+
}
423+
}
424+
425+
pointer.stateNode.classList.add(rtid)
417426
}
418427
pointer = pointer.child
419428
}
420429
} else {
421430
if (currentFiber.child && currentFiber.child.stateNode && currentFiber.child.stateNode.setAttribute) {
422-
rtid = "fromLinkFiber" + rtidCounter
423-
currentFiber.child.stateNode.setAttribute("id", rtid);
431+
432+
rtid = "fromLinkFiber" + rtidCounter;
433+
// check if rtid is already present
434+
// remove existing rtid before adding a new one
435+
if (currentFiber.child.stateNode.classList.length > 0) {
436+
let lastClass = currentFiber.child.stateNode.classList[currentFiber.child.stateNode.classList.length -1];
437+
console.log("lastClass: ", lastClass, "linkFiber class? ", lastClass.includes("fromLinkFiber"));
438+
if (lastClass.includes("fromLinkFiber")) {
439+
currentFiber.child.stateNode.classList.remove(lastClass);
440+
}
424441
}
442+
currentFiber.child.stateNode.classList.add(rtid);
443+
}
425444
rtidCounter++;
426445
}
427446
// checking if tree fromSibling is true

0 commit comments

Comments
 (0)