@@ -356,7 +356,6 @@ function createTree(
356
356
isRecoil === false
357
357
) {
358
358
if ( memoizedState . queue ) {
359
- // console.log("line 357...")
360
359
// Hooks states are stored as a linked list using memoizedState.next,
361
360
// so we must traverse through the list and get the states.
362
361
// We then store them along with the corresponding memoizedState.queue,
@@ -411,17 +410,37 @@ function createTree(
411
410
412
411
while ( pointer !== null ) {
413
412
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 )
417
426
}
418
427
pointer = pointer . child
419
428
}
420
429
} else {
421
430
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
+ }
424
441
}
442
+ currentFiber . child . stateNode . classList . add ( rtid ) ;
443
+ }
425
444
rtidCounter ++ ;
426
445
}
427
446
// checking if tree fromSibling is true
0 commit comments