Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fix: save latest value when close settings panel (#2770)

Bogdan Chadkind83b911f4811
diff --git a/apps/builder/app/builder/features/settings-panel/shared.tsx b/apps/builder/app/builder/features/settings-panel/shared.tsx
index a9d4bee361..8d0eaeede6 100644
--- a/apps/builder/app/builder/features/settings-panel/shared.tsx
+++ b/apps/builder/app/builder/features/settings-panel/shared.tsx
@@ -181,8 +181,14 @@ export const useLocalValue = <Type,>(
// onBlur will not trigger if control is unmounted when props panel is closed or similar.
// So we're saving at the unmount
- // eslint-disable-next-line react-hooks/exhaustive-deps
- useEffect(() => save, []);
+ // store save in ref to access latest saved value from render
+ // instead of stale one
+ const saveRef = useRef(save);
+ saveRef.current = save;
+ useEffect(() => {
+ // access ref in the moment of unmount
+ return () => saveRef.current();
+ }, []);
useEffect(() => {
// Update local value if saved value changes and control is not in edit mode.