Issue #4249πŸ’¬ AnsweredOpened April 8, 2022by iamqinglong0 reactions

Image src won't change in exported HTML

Quick answerby m-jojo-s

either use selected.set('src', doc.url) or enable unsafe html attributes Refer to #4148

Read full answer below ↓

Question

GrapesJS version

  • I confirm to use the latest version of GrapesJS

What browser are you using?

chrome 100

Reproducible demo link

https://grapesjs.com/demo.html

Describe the bug

How to reproduce the bug? 0. I am using external

  1. Drag an image block to canvas
  2. Select an image from the custom modal
  3. View the code
  4. Check the model/target object attributes

What is the expected behavior? The src attribute of the exported code should contain the actual url <img src="actual-url" />

What is the current behavior? I am using an external module for custom asset manager.

The model/target src attribute should contain the actual url <img width="682" alt="Screen Shot 2022-04-08 at 2 26 08 PM" src="https://user-images.githubusercontent.com/48402616/162377084-c1eff1fe-3084-468e-8f27-ea287dda62f6.png">

but the exported html has the placeholder base64 as src attribute <img width="616" alt="Screen Shot 2022-04-08 at 2 35 55 PM" src="https://user-images.githubusercontent.com/48402616/162378381-861f5a70-0857-4fe2-a0f6-cec1d13182ab.png">

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

The config:

assetManager: {
        custom: {
          open: (props) => {
            this.showAddMedia = true;
          },
          close: (props) => {
            this.showAddMedia = false;
          }
        },
      },

Adding the src attribute

 setMedia(doc) {
  const selected = this.editor.getSelected();
  selected.addAttributes({ src: doc.url });
  console.log(selected)
  console.log(selected.toHTML())
  this.editor.AssetManager.close()
},
closeMediaModal() {
  this.editor.AssetManager.close()
}

Code of Conduct

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

Answers (3)

m-jojo-sβ€’ April 8, 2022

either use selected.set('src', doc.url) or enable unsafe html attributes

Refer to #4148

artfβ€’ April 8, 2022

Yeah, I'd say you should simply switch to selected.set('src', doc.url) as already suggested.

ClaudeCodeβ€’ May 17, 2026

Thanks for reporting this, @iamqinglong.

Great question about image src won't change in exported HTML. The recommended approach with ProseMirror 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 β†’

Related tutorials

In-depth guides on the same topic.

All tutorials β†’

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.