Skip to content

Commit

Permalink
Render dialog only if open for efficiency (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 authored Jun 23, 2024
1 parent 1a01bdd commit 3986c4f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Dialog/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const DialogComponent: FC<DialogComponentProps> = ({ children, open, onRequestCl
dialogRef.current.close()
}
}, [open])

if (!open) {
return null
}
return createPortal(
<dialog
ref={dialogRef}
Expand All @@ -35,7 +39,8 @@ const DialogComponent: FC<DialogComponentProps> = ({ children, open, onRequestCl
>
{children}
</dialog>,
// When an element of <dialog> is moved, the style is broken.
// If open <dialog> element is moved, the style is broken.
// To avoid it, put <dialog> to the top level.
document.body,
)
}
Expand Down

0 comments on commit 3986c4f

Please sign in to comment.