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 breakpoints width and rendering (#1631)

Bogdan Chadkinf9add7acdd76
diff --git a/apps/builder/app/builder/features/breakpoints/use-set-initial-canvas-width.ts b/apps/builder/app/builder/features/breakpoints/use-set-initial-canvas-width.ts
index b78399f70d..db713db5ce 100644
--- a/apps/builder/app/builder/features/breakpoints/use-set-initial-canvas-width.ts
+++ b/apps/builder/app/builder/features/breakpoints/use-set-initial-canvas-width.ts
@@ -6,9 +6,11 @@ import {
workspaceRectStore,
canvasWidthStore,
} from "~/builder/shared/nano-states";
-import { breakpointsStore } from "~/shared/nano-states";
+import {
+ breakpointsStore,
+ selectedBreakpointStore,
+} from "~/shared/nano-states";
import { findInitialWidth } from "./find-initial-width";
-import { isBaseBreakpoint } from "~/shared/breakpoints";
// Set canvas width based on workspace width, breakpoints and passed breakpoint id.
export const useSetInitialCanvasWidth = () => {
@@ -47,14 +49,14 @@ export const useSetCanvasWidth = () => {
return;
}
const breakpointValues = Array.from(breakpoints.values());
- const baseBreakpoint = breakpointValues.find(isBaseBreakpoint);
+ const selectedBreakpoint = selectedBreakpointStore.get();
- // When there is base breakpoint, we want to find the lowest possible size
+ // When there is selected breakpoint, we want to find the lowest possible size
// that is bigger than all max breakpoints and smaller than all min breakpoints.
- if (baseBreakpoint) {
+ if (selectedBreakpoint) {
const width = findInitialWidth(
breakpointValues,
- baseBreakpoint,
+ selectedBreakpoint,
workspaceRect.width
);
@@ -71,16 +73,14 @@ export const useSetCanvasWidth = () => {
if (workspaceRect === undefined) {
return;
}
- unsubscribeRectStore();
+ unsubscribeRectStore?.();
update();
})
- : () => {
- /**/
- };
+ : undefined;
return () => {
unsubscribeBreakpointStore();
- unsubscribeRectStore();
+ unsubscribeRectStore?.();
};
}, []);
};
diff --git a/apps/builder/app/canvas/shared/styles.ts b/apps/builder/app/canvas/shared/styles.ts
index a4b27b3911..1818a8414d 100644
--- a/apps/builder/app/canvas/shared/styles.ts
+++ b/apps/builder/app/canvas/shared/styles.ts
@@ -27,10 +27,11 @@ import {
selectedStyleSourceSelectorStore,
} from "~/shared/nano-states";
import {
- createCssEngine,
- toValue,
type StyleRule,
type PlaintextRule,
+ createCssEngine,
+ toValue,
+ compareMedia,
} from "@webstudio-is/css-engine";
import { useSubscribe } from "~/shared/pubsub";
@@ -118,7 +119,10 @@ export const GlobalStyles = () => {
const assets = useStore(assetsStore);
useIsomorphicLayoutEffect(() => {
- for (const breakpoint of breakpoints.values()) {
+ const sortedBreakpoints = Array.from(breakpoints.values()).sort(
+ compareMedia
+ );
+ for (const breakpoint of sortedBreakpoints) {
userCssEngine.addMediaRule(breakpoint.id, breakpoint);
}
userCssEngine.render();