Issue #3975πŸ’¬ AnsweredOpened November 25, 2021by Sudhin350 reactions

Background Image Starts duplicating in all the pages if we add only for one page

Quick answerby artf

Please check this option first https://grapesjs.com/docs/modules/Selectors.html#component-first-selectors In case you still have problems, open a proper bug issue with a reproducible demo link.

Read full answer below ↓

Question

GrapesJS version

  • I confirm to use the latest version of GrapesJS

What browser are you using?

Chrome v9

Reproducible demo link

Nothing

Describe the bug

How to reproduce the bug?

  1. Implement the multipage concept
  2. Create the 3 pages
  3. Click on the background image in decorations ( Style Manager ) and add it to first page
  4. Now add the new page or click on the second page or third page

What is the expected behavior? The background image should not be duplicated to all pages , it should add it to only that selected page

What is the current behavior? The background image is added to all pages when added to only page

If is necessary to execute some code in order to reproduce the bug, paste it here below:

const editor = grapesjs.init({
            container: "#block",
            plugins: ['gjs-preset-webpage'], // @AS Preset need to add for predefined components
            // fromElement: 1,
            avoidInlineStyle: 1,
            blockManager: {
              // appendTo: '.text-block-manager',
              // ignoreCategories: true,
            },
            cssIcons: null,
            canvas: {
              styles: [
                "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
                "http://localhost:3009/api/v1/html/1/styles/canvas.css",
              ],
              scripts: [
                "https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js",
                "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js",
              ],
            },
            protectedCss: "",
            canvasCss: `
            .gjs-selected {
              outline: 2px solid #FF1430 !important;
              outline-offset: -2px !important;
               }
               .gjs-hovered{
              }`,
            commands: {
              defaults: [
                {
                  id: "my-command-id",
                  run() {
                    alert("This is my command");
                  },
                },
              ],
            },
            storageManager: {
              id: "gjs_",
              type: "remote",
              autosave: true,
              autoload: false,
              urlStore: this.API_URL + "update_builder/" + this.state.id,
              urlLoad: this.API_URL + this.state.id,
              //method: 'patch',
              params: {
                draft: "1",
              },
              headers: { Authorization: localStorage.getItem("token") },
            },
            assetManager: {
              storageType: "",
              storeOnChange: true,
              storeAfterUpload: true,
              upload: process.env.REACT_APP_ASSET_PATH, //for temporary storage
              assets: [],
              uploadName: "file",
              uploadFile: function (e) {
                var files = e.dataTransfer
                  ? e.dataTransfer.files
                  : e.target.files;
                var formData = new FormData();
                for (var i in files) {
                  formData.append("upload", files[i]); 
                }
                PageService.contentUpload(
                  formData,
                  localStorage.getItem("token")
                )
                  .then((response) => {
                    var imageUpload = response.data.path.replace(/[//:-]/g, "");
                    var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.jpe?g|png|gif|bmp)$/;
                    if (regex.test(imageUpload.toLowerCase())) {
                    editor.AssetManager.add(response.data.path);
                   } else {
                        alert("Please upload valid images.");
                      }
                  })
                  .catch((error) => {
                    alert("Please upload valid images.");
                    // CommonService.logout(error);
                  });
              },
            },
            pageManager: {
              pages: this.pagesList,
            },
            layerManager: {
              appendTo: ".layers-container",
            },
            traitManager: {
              appendTo: ".traits-container",
            },
            selectorManager: {
              appendTo: ".selectors-container",
            },
            styleManager: {
              appendTo: ".styles-container",
            },
            deviceManager: {
              devices: [],
            },
          });
          const panel = editor.Panels;
          const pageManager = editor.Pages;
          /*AS to set canvas freely dragging absolute or translate*/
          editor.getModel().set("dmode", "translate");
          // editor storage error redirect user to login screen.
          editor.on("storage:error", (err) => {
            alert(`Error: Token Expired, Please Login Again`);
            localStorage.clear();
            window.location.href = process.env.REACT_APP_SSO_LOGIN_URL;
          });



         
          editor.on("storage:start:store", (objectToStore, abcd) => {
            this.getPageById();
          });

          // Remove top default buttons
          panel.removeButton("views", "open-layers");
          panel.removeButton("options", "export-template");
          panel.removeButton("options", "fullscreen");
          // panel.removeButton("options", "sw-visibility");
          panel.removeButton("views", "open-sm");
          panel.removeButton("views", "open-blocks");
          panel.removeButton("views", "open-tm");
          panel.removeButton("options", "preview");

          editor.Commands.add('core:canvas-clear', {
            run(e) {
              e.DomComponents.clear();
              e.CssComposer.clear();
              e.setComponents(`<div class="container-fluid vh-100"></div>`)
            }
          });
          
          const pagesList = pageManager.getAll();
          this.pages = pagesList;
          this.pageName = this.pages[0].attributes.name;
          this.editorData = editor;


          editor.Commands.add("preview-ext", {
            run(e) {
              e.runCommand("preview");
            },
          });
          panel.addButton("options", {
            id: "preview",
            className: "fa fa-eye",
            command: (e) => e.runCommand("preview-ext"),
            attributes: { title: "Preview", 'data-tip':"Preview", 'data-for':"builderTT" },
          });

          editor.on("run:preview", () => {
            self.previewPerform("none");
          });
          editor.on("stop:preview", () => {
            self.previewPerform("block");
          });

          panel.addButton("options", {
            id: "link-button",
            command: {
              run: function (editor) {
                GenerateLink(self.state);
              },
            },
            attributes: { id: "generate-link", class: "fa-link", 'data-tip':"Publish Page", 'data-for':"builderTT" },
       )}
            }
          
          });


 newpage(){
const pagesLength = this.editorData.Pages.getAll().length;
    this.editorData.Pages.add({
      id: `page-${pagesLength + 1}`,
      name: `Page ${pagesLength + 1}`,
      styles: ``,
      component: ``,
    });
![Uploading Background_image_issue.png…]()

}

Code of Conduct

  • I agree to follow this project's Code of Conduct

Answers (2)

ClaudeCodeβ€’ May 17, 2026

Thanks for reporting this, @Sudhin35.

Great question about Background Image Starts duplicating in all the pages if we add only for one page. The recommended approach with StyleManager is to use the event-driven API.

Start here:

  1. Check the GrapesJS documentation for your specific module
  2. Look for the on() event listener method
  3. Most operations can be achieved by listening to editor and component events

Common patterns:

// Listen for changes
editor.on('change', () => console.log('something changed'));

// Component lifecycle
editor.on('component:mount', (c) => console.log('component ready', c));
editor.on('component:update', (c) => console.log('component updated', c));

If you're still stuck:

  • Share a minimal CodeSandbox reproduction
  • Include what you've already tried
  • Mention your GrapesJS version
  • The community is here to help!

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins β†’
Premium option

Premium plugins ship with support, regular updates, and production-ready features β€” save days of integration work.

Browse premium plugins β†’

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.