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 stale unit change in scrub logic

Oleg Isonena728dbfac734
diff --git a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
index 3d89bbbe53..6e255a0877 100644
--- a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
@@ -18,22 +18,22 @@ export const TextControl = ({
const setValue = setProperty(styleConfig.property);
- const [ephemeralValue, setEphemeralValue] = useState<StyleValue | null>(null);
+ const [currerntValue, setCurrentValue] = useState<StyleValue>();
return (
<CssValueInput
property={styleConfig.property}
- value={ephemeralValue ?? value}
+ value={currerntValue ?? value}
keywords={styleConfig.items.map((item) => ({
type: "keyword",
value: item.name,
}))}
onChange={(styleValue) => {
- setEphemeralValue(styleValue);
+ setCurrentValue(styleValue);
setValue(toValue(styleValue), { isEphemeral: true });
}}
onItemHighlight={(styleValue) => {
- const nextValue = styleValue ?? ephemeralValue ?? value;
+ const nextValue = styleValue ?? currerntValue ?? value;
if (nextValue) {
setValue(toValue(nextValue), {
isEphemeral: true,
@@ -41,7 +41,7 @@ export const TextControl = ({
}
}}
onChangeComplete={(styleValue) => {
- setEphemeralValue(null);
+ setCurrentValue(undefined);
setValue(toValue(styleValue));
}}
/>
diff --git a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx
index 78b21b1fc7..5a874b95c1 100644
--- a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx
+++ b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx
@@ -83,15 +83,11 @@ const useScrub = (options: {
}) => {
const inputRef = useRef<HTMLInputElement | null>(null);
const optionsRef = useRef(options);
-
- useEffect(() => {
- optionsRef.current = options;
- }, [options]);
+ optionsRef.current = options;
useEffect(() => {
const { value, onChange, onChangeComplete } = optionsRef.current;
if (value.type !== "unit" || inputRef.current === null) return;
-
const scrub = numericScrubControl(inputRef.current, {
initialValue: value.value,
onValueInput(event) {
@@ -109,7 +105,7 @@ const useScrub = (options: {
});
return scrub.disconnectedCallback;
- }, [options.value.type]);
+ }, [options.value.type, options.value?.unit]);
return inputRef;
};