Skip to content

don't recreate hostElements each time #4033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sweet-onions-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': patch
---

Fixed confirm() leaving <div>s in the DOM.
2 changes: 1 addition & 1 deletion src/ConfirmationDialog/ConfirmationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export type ConfirmOptions = Omit<ConfirmationDialogProps, 'onClose'> & {content
async function confirm(themeProps: ThemeProviderProps, options: ConfirmOptions): Promise<boolean> {
const {content, ...confirmationDialogProps} = options
return new Promise(resolve => {
hostElement = document.createElement('div')
hostElement ||= document.createElement('div')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never used this operator. I love it!

if (!hostElement.isConnected) document.body.append(hostElement)
const root = createRoot(hostElement)
const onClose: ConfirmationDialogProps['onClose'] = gesture => {
Expand Down