React version: 18.3.0-next-3ba7add60-20221201

Hard to reproduce.

In Next.js, in rare cases, and only after a fast refresh, the ref object when using forwardRef is simply `{}`.

This leads to the `TypeError: can't define property "current": Object is not extensible` error when used with `useImperativeHandle`.

```tsx
function Parent() {
  const carouselRef = useRef<any>();

  return <Suspense><Carousel ref={carouselRef} /></Suspense>
}

const Carousel = forwardRef((props, ref) => {
  if (!('current' in ref)) { debugger; }
  const thing = use(aPromise);
  return ...;
});
```

![Screenshot 2023-03-17 at 18 49 21](https://user-images.githubusercontent.com/5406212/225981809-22f575fa-0ec7-4f94-ae23-bffc8bf7c4dd.png)

In `updateImperativeHandle`, the ref is already an empty object.

![Screenshot 2023-03-17 at 19 13 13](https://user-images.githubusercontent.com/5406212/225985622-b8512a61-3a6b-4958-b63f-277219d4c816.png)

I haven't investigated it further yet, the stacktraces are quite hard to follow.
const eventTime = requestEventTime();
        if (root !== null) {
          markRootUpdated(root, SyncLane, eventTime);
          ensureRootIsScheduled(root);
        }
        return;
      }
    }
    fiber = fiber.return;
  }
  if (__DEV__) {
    console.error(
      'Internal React error: Attempted to capture a commit phase error ' +
        'inside a detached tree. This indicates a bug in React. Potential ' +
        'causes include deleting the same fiber more than once, committing an ' +
        'already-finished tree, or an inconsistent return pointer.\n\n' +
        'Error message:\n\n%s',
      error,
    );
  }
}
export function attachPingListener(
  root: FiberRoot,
  wakeable: Wakeable,
  lanes: Lanes,
) {
   Attach a ping listener
  
   The data might resolve before we have a chance to commit the fallback. Or,
   in the case of a refresh, we'll never commit a fallback. So we need to