### Website or app

Please checkout the linked branch not `main`
https://github.com/eps1lon/react-devtools-repro-no-matching-node/tree/repro/elements-leaking
Repro steps and screen recording included in the repro

### Repro steps

1. Clone repro
1. yarn
1. yarn start
1. Open app page
1. open devtools
1. Uncomment the `useEffect` block i.e. add an effect
1. inspect `Component` element
1. comment `useEffect` block i.e. remove the effect
1. Repeat comment/uncomment to see that children grow indefinitely


### How often does this bug happen?

Every time

### DevTools package (automated)

_No response_

### DevTools version (automated)

_No response_

### Error message (automated)

Could not inspect element with id 4

### Error call stack (automated)

_No response_

### Error component stack (automated)

_No response_

### GitHub query string (automated)

_No response_

Might be a duplicate of https://github.com/facebook/react/issues/21436#issuecomment-835406075 since the repro steps are the same. But depending on what the effect is doing, the behavior is different.
case HostRoot:
         Roo
         Ins
        const id = getFiberID(getPrimaryFiber(fiber));
        const pseudoKey = rootPseudoKeys.get(id);
        if (pseudoKey === undefined) {
          throw new Error('Expected mounted root to have known pseudo key.');
        }
        displayName = pseudoKey;
        break;
      case HostComponent:
        displayName = fiber.type;
        break;
      default:
        break;
    }
    return {
      displayName,
      key,
      index,
    };
  }
   Produces a serializable representation that does a best effort
   of identifying a particular Fiber between page reloads.
   The return path will contain Fibers that are "invisible" to the store
   because their keys and indexes are important to restoring the selection.
  function getPathForElement(id: number): Array<PathFrame> | null {
    let fiber = idToFiberMap.get(id);
    if (fiber == null) {
      return null;