Skip to content

Commit e9ca015

Browse files
authored
fix: Fixes saving binding when closing popover by click outside (#4941)
## Description <img width="518" alt="image" src="https://github.com/user-attachments/assets/9326dd07-2244-4f57-ae93-a9ab3bf0f38d" /> When you are creating a binding from inside a variable dialog and having popover opened from a popover, when you click outside, binding won't be saved ## Steps for reproduction 1. create resource variable 2. close 3. edit that variabel 4. bind url 5. click outside of both popovers 6. see changes were saved ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 88cf253 commit e9ca015

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/design-system/src/components/dialog.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const DialogContext = createContext<{
6767
export const Dialog = ({
6868
resize,
6969
draggable,
70+
onOpenChange,
7071
...props
7172
}: ComponentProps<typeof Primitive.Dialog> & {
7273
resize?: "both" | "none";
@@ -77,7 +78,20 @@ export const Dialog = ({
7778
<DialogContext.Provider
7879
value={{ isMaximized, setIsMaximized, resize, draggable }}
7980
>
80-
<Primitive.Dialog {...props} />
81+
<Primitive.Dialog
82+
{...props}
83+
onOpenChange={(open) => {
84+
// When dialog closes, there can be state changes in the content that haven't rendered yet.
85+
// In that case we might close the dialog without saving the form changes.
86+
// Currently known example is binding popover that opens from variable popover. Second popover gets
87+
// closed by unmounting if we click outside and first popover doesn't get the changes because it is trying to render
88+
// the value in a form and serialize the form using FormData.
89+
// With this we are giving React's render cycle time to render the state before we close the dialog.
90+
requestAnimationFrame(() => {
91+
onOpenChange?.(open);
92+
});
93+
}}
94+
/>
8195
</DialogContext.Provider>
8296
);
8397
};

0 commit comments

Comments
 (0)