Instatic icon indicating copy to clipboard operation
Instatic copied to clipboard

[Bug]: ditor canvas ignores node inline styles on images — explicit styleprop clobbersnodeWrapperProps.style` in ImageEditor

Open borskyj opened this issue 4 months ago • 0 comments

Summary

In the design canvas, base.image nodes ignore their per-node inline styles (inlineStyles) once the media asset resolves. The published output is correct — this is an editor-only WYSIWYG break.

Cause

src/modules/base/image/ImageEditor.tsx, resolved-asset branch:

return (
  <img
    {...nodeWrapperProps}
    {...htmlAttrs}
    src={responsive.src}
    ...
    style={style}   // ← always wins over nodeWrapperProps.style
  />
)

Steps to reproduce

  1. Add a base.image node and give it inline styles, e.g. a header logo with height: 1.75rem; width: auto; display: block.
  2. Publish → the live page renders the logo at 1.75rem. Correct.
  3. Open the page in the editor → the canvas renders the image at its intrinsic size (a 2000px-wide logo fills the whole frame), ignoring the inline styles.

The styles briefly apply while the asset cache is still loading, then get dropped the moment the asset resolves — which is a hint at the cause.

Expected behavior

The editor canvas renders the image with the node's inline styles applied, matching the published page — e.g. a header logo with height: 1.75rem; width: auto; display: block displays at 1.75rem tall in the canvas, exactly as it does on the published site.

Actual behavior

Once the media asset resolves, the canvas drops the node's inline styles and renders the image at its intrinsic size (a 2000px-wide logo fills the entire frame). The inline styles do apply for a brief moment while the asset cache is still loading, then disappear the instant the asset resolves. The published page is unaffected — this is an editor-only WYSIWYG break.

Cause: in src/modules/base/image/ImageEditor.tsx, resolved-asset branch, the explicit style={style} prop comes after the {...nodeWrapperProps} spread:

<img
  {...nodeWrapperProps}
  ...
  style={style}   // ← always overrides nodeWrapperProps.style
/>

nodeWrapperProps.style is the channel that carries node.inlineStyles into the canvas, but the explicit prop always wins — both when style is the BlurHash backdrop object and when it is undefined (an explicit style={undefined} still overrides a spread value in React). The raw-src fallback branch (asset not yet resolved) has no explicit style prop, which is why the styles flash on and then vanish.

Suggested fix: merge instead of clobber — spread nodeWrapperProps?.style into the backdrop object, and pass nodeWrapperProps?.style through when there is no backdrop.

Version or commit

No response

Deployment mode

None

Logs or screenshots


borskyj avatar Jul 24 '26 07:07 borskyj