Skip to content

Commit aa0f2b5

Browse files
committed
Implement comprehensive cleanup for pointer events and overlays in AgentList2 and NewAgentSheet components
- Added cleanup effects to reset pointer events, cursor, and overflow styles when components unmount. - Enhanced the handling of overlays and portals to ensure proper cleanup and prevent interaction issues. - Introduced delays in cleanup processes to ensure UI responsiveness and consistency.
1 parent e0ab154 commit aa0f2b5

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

webapp/src/components/AgentList2.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ export default function AgentList2({ agents, fetchAgents }) {
137137
);
138138
}, [searchTerm]);
139139

140+
// Cleanup effect to reset pointer events when component unmounts
141+
useEffect(() => {
142+
return () => {
143+
document.body.style.pointerEvents = 'auto';
144+
document.body.style.cursor = 'auto';
145+
document.body.style.overflow = 'visible';
146+
};
147+
}, []);
148+
140149
async function deleteAgent(agentId) {
141150
if (!agentId) return;
142151

@@ -326,6 +335,36 @@ export default function AgentList2({ agents, fetchAgents }) {
326335
} else {
327336
setOpenNewAgentSheet(open);
328337
}
338+
339+
// Additional check for pointer events with comprehensive cleanup
340+
setTimeout(() => {
341+
if (document.body.style.pointerEvents === 'none') {
342+
document.body.style.pointerEvents = 'auto';
343+
}
344+
345+
// Additional cleanup
346+
document.body.style.cursor = 'auto';
347+
document.body.style.overflow = 'visible';
348+
349+
// Clean up any remaining overlays
350+
const overlays = document.querySelectorAll('[data-radix-dialog-overlay]');
351+
overlays.forEach(overlay => {
352+
if (overlay instanceof HTMLElement) {
353+
overlay.style.pointerEvents = 'none';
354+
}
355+
});
356+
357+
// Clean up any remaining portals
358+
const portals = document.querySelectorAll('[data-radix-portal]');
359+
portals.forEach(portal => {
360+
if (
361+
portal instanceof HTMLElement &&
362+
!portal.querySelector('[data-radix-dialog-content]')
363+
) {
364+
portal.remove();
365+
}
366+
});
367+
}, 50);
329368
}}
330369
editing={!!selectedAgent}
331370
agentId={selectedAgent?._id}

webapp/src/components/agents/NewAgentSheet.tsx

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,15 @@ export const AgentSheet = ({
477477
}
478478
}, []);
479479

480+
// Cleanup effect to reset pointer events when component unmounts
481+
useEffect(() => {
482+
return () => {
483+
document.body.style.pointerEvents = 'auto';
484+
document.body.style.cursor = 'auto';
485+
document.body.style.overflow = 'visible';
486+
};
487+
}, []);
488+
480489
function showPreview(e: React.ChangeEvent<HTMLInputElement>) {
481490
const file = e.target.files?.[0];
482491
if (file) {
@@ -496,6 +505,7 @@ export const AgentSheet = ({
496505
open={openEditSheet}
497506
onOpenChange={open => {
498507
setOpenEditSheet(open);
508+
499509
// Reset form state when sheet closes
500510
if (!open) {
501511
setToolState(null);
@@ -506,6 +516,30 @@ export const AgentSheet = ({
506516
setIcon(null);
507517
setAllowDelegation(false);
508518
setVerbose(false);
519+
520+
// Force reset pointer events and cursor with delay
521+
setTimeout(() => {
522+
// Force reset pointer events if they're blocked
523+
if (document.body.style.pointerEvents === 'none') {
524+
document.body.style.pointerEvents = 'auto';
525+
}
526+
527+
// Force reset overflow if it's hidden
528+
if (document.body.style.overflow === 'hidden') {
529+
document.body.style.overflow = 'visible';
530+
}
531+
532+
// Additional cleanup for cursor
533+
document.body.style.cursor = 'auto';
534+
535+
// Force cleanup of any remaining overlays
536+
const overlays = document.querySelectorAll('[data-radix-dialog-overlay]');
537+
overlays.forEach(overlay => {
538+
if (overlay instanceof HTMLElement) {
539+
overlay.style.pointerEvents = 'none';
540+
}
541+
});
542+
}, 100);
509543
}
510544
}}>
511545
{modal}
@@ -527,7 +561,19 @@ export const AgentSheet = ({
527561
</SheetTrigger>
528562
)}
529563

530-
<SheetContent size='md' className='text-foreground overflow-y-auto'>
564+
<SheetContent
565+
size='md'
566+
className='text-foreground overflow-y-auto'
567+
style={{
568+
pointerEvents: 'auto',
569+
overflow: 'visible'
570+
}}
571+
onPointerDownOutside={() => {
572+
document.body.style.pointerEvents = 'auto';
573+
}}
574+
onEscapeKeyDown={() => {
575+
document.body.style.pointerEvents = 'auto';
576+
}}>
531577
<SheetHeader>
532578
<SheetTitle>
533579
<div className='flex items-center gap-2'>

0 commit comments

Comments
 (0)