mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-07 08:26:51 +00:00
fix: ensure checkpoint restore popover works when portal container is not immediately available
- Updated useRooPortal hook to use MutationObserver to watch for portal element - Added fallback to undefined when portal container is null in CheckpointMenu - Fixes issue where clicking on checkpoints does nothing Fixes #8563
This commit is contained in:
parent
eeaafef786
commit
a42a50ed1b
2 changed files with 31 additions and 5 deletions
|
|
@ -86,7 +86,7 @@ export const CheckpointMenu = ({
|
|||
</Button>
|
||||
</PopoverTrigger>
|
||||
</StandardTooltip>
|
||||
<PopoverContent align="end" container={portalContainer}>
|
||||
<PopoverContent align="end" container={portalContainer || undefined}>
|
||||
<div className="flex flex-col gap-2">
|
||||
{!isCurrent && (
|
||||
<div className="flex flex-col gap-1 group hover:text-foreground">
|
||||
|
|
|
|||
|
|
@ -1,10 +1,36 @@
|
|||
import { useState } from "react"
|
||||
import { useMount } from "react-use"
|
||||
import { useState, useEffect } from "react"
|
||||
|
||||
export const useRooPortal = (id: string) => {
|
||||
const [container, setContainer] = useState<HTMLElement>()
|
||||
const [container, setContainer] = useState<HTMLElement | null>(null)
|
||||
|
||||
useMount(() => setContainer(document.getElementById(id) ?? undefined))
|
||||
useEffect(() => {
|
||||
// Try to find the element immediately
|
||||
const element = document.getElementById(id)
|
||||
if (element) {
|
||||
setContainer(element)
|
||||
return
|
||||
}
|
||||
|
||||
// If not found, set up a MutationObserver to watch for it
|
||||
const observer = new MutationObserver(() => {
|
||||
const element = document.getElementById(id)
|
||||
if (element) {
|
||||
setContainer(element)
|
||||
observer.disconnect()
|
||||
}
|
||||
})
|
||||
|
||||
// Start observing the document body for changes
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
})
|
||||
|
||||
// Cleanup
|
||||
return () => {
|
||||
observer.disconnect()
|
||||
}
|
||||
}, [id])
|
||||
|
||||
return container
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue