MediaCondition: "min-width" breakpoints not applying the correct style in canvas
We should apply the same logic from https://github.com/artf/grapesjs/blob/201e1f9a61783080f7be885e9e0be9a40ecc16cc/src/codemanager/model/CssGenerator.js#L151-L162 here https://github.com/artf/grapesjs/blob/201e1f9a61783080f7be885e9e0be9a40ecc16cc/src/csscomposer/view/CssRulesView.js#L122-L129
Read full answer below ↓Question
Hi,
I'm having some issue with mobile first approach. The canvas render the wrong style when setting different styles at multiple breakpoints. But the code generated is good, this issue only happen in the canvas.
https://codesandbox.io/s/xenodochial-shockley-s02lp?file=/index.js:496-524
const breakpoints = [
{ name: "xs", width: "320px" },
{ name: "xsLg", width: "400px" },
{ name: "sm", width: "630px" },
{ name: "md", width: "740px" },
{ name: "lg", width: "1024px" },
{ name: "xl", width: "1280px" },
{ name: "xxl", width: "1800px" }
];
const editor = grapesjs.init({
container: "#gjs",
fromElement: 1,
storageManager: { type: 0 },
mediaCondition: "min-width",
deviceManager: { devices: breakpoints },
plugins: ["gjs-blocks-basic"]
});

- Are you using the latest release (older versions are NOT supported)? Yes using 0.16.12
- Are you facing the bug with your local copy of GrapesJS or with the current demo? With my local copy
- If a local copy
- Indicate all informations about your OS, browser and GrapesJS version.
MacOs, tried on firefox and Chrome and same issue
- Indicate all informations about your OS, browser and GrapesJS version.
- What is the expected behavior? Still should change according to the breakpoint in the canvas when using mediaCondition: "min-width"
- What happens instead? Style in canvas only apply the change from the 1st breakpoint. but the code in the export view is right. The issue is only in how the canvas render.
- If you're able to reproduce the bug indicate all the necessary steps
- Follow this codesandbox https://codesandbox.io/s/xenodochial-shockley-s02lp?file=/index.js:496-524
- Change the device to xs
- Select the copy box and change the color of this one
- Change the device to md
- Select the copy box and change the color of this one to a new color, the color is still the old one from xs
- Desktop first works fine
Thanks a lot for your help
Answers (1)
Related Questions and Answers
Continue research with similar issue discussions.
Issue #896
[BUG] Media query rules are overridden by class rules in canvas
Hi @artf , I've noticed an issue while testing one of my templates using different device configurations that supposed to trigger media que...
Issue #1506
Css Media Query Issue
Hello @artf There is an issue on demo page as well as library in media query. Issue is that if user update style on mobile view first and t...
Issue #2656
[BUG] Wrong position of toolbar when duplicate children component
Hi, you can check this example: https://codepen.io/abozhinov/pen/XWbqjEJ Steps to reproduce the problem:If components existing delete them...
Issue #2824
Dragging items do not position on intital drag?
So when I drag a component/item from the bar to the center it will not go where I told it to go... IT always goes about 20% page width to o...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Related tutorials
In-depth guides on the same topic.
Tutorial
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Tutorial
GrapesJS Inline RTE Plugins Update: CKEditor 5 v0.1.4 and Froala Inline Text Editor
CKEditor 5 Inline for GrapesJS v0.1.4 fixes Studio SDK toolbar clipping, iframe injection and link balloon bugs. Compare with Froala Inline — both $69.
Tutorial
Embed GrapesJS in Your SaaS: A Weekend Guide
Embed GrapesJS in your SaaS and ship a white-label page builder over a weekend. Honest tradeoffs, real code, and the plugins that close the UX gap.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.