Skip to content

fix: Fixes saving binding when closing popover by click outside #4941

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 3 commits into from
Mar 6, 2025
Merged
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
16 changes: 15 additions & 1 deletion packages/design-system/src/components/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const DialogContext = createContext<{
export const Dialog = ({
resize,
draggable,
onOpenChange,
...props
}: ComponentProps<typeof Primitive.Dialog> & {
resize?: "both" | "none";
Expand All @@ -77,7 +78,20 @@ export const Dialog = ({
<DialogContext.Provider
value={{ isMaximized, setIsMaximized, resize, draggable }}
>
<Primitive.Dialog {...props} />
<Primitive.Dialog
{...props}
onOpenChange={(open) => {
// When dialog closes, there can be state changes in the content that haven't rendered yet.
// In that case we might close the dialog without saving the form changes.
// Currently known example is binding popover that opens from variable popover. Second popover gets
// closed by unmounting if we click outside and first popover doesn't get the changes because it is trying to render
// the value in a form and serialize the form using FormData.
// With this we are giving React's render cycle time to render the state before we close the dialog.
requestAnimationFrame(() => {
onOpenChange?.(open);
});
}}
/>
</DialogContext.Provider>
);
};
Expand Down