Issue #3278Opened February 18, 2021by Dmurl50 reactions

BUG: Custom component view onRender is called early

Question

Version:

Reproduced in codepen below using 0.16.34 (returned from https://unpkg.com/grapesjs) and 0.16.22 in a Preact project

Describe the bug detailed

A custom GrapesJS component calls its view's "onRender" function when the component is rendered to the canvas. Per the documentation:

image

I would expect this to be called once a component has fully finished rendering to the canvas and all dimensions and position attributes have been determined. However, as seen in the reproduction code pen below, onRender() is called before the element's dimensions have been determined, and the element registers a size of 0/0 height/width. This causes any inner elements to not be able to register the size of the container properly, which can impact inner components that rely on that information. Current onRender() seems more like "onDOMAttachment()" as opposed to a lifecycle hook for a component being "rendered to the canvas".

My use case is a ChartJS instance that renders inside of an editor component, but the responsive sizing system in ChartJS completely breaks when attached in onRender() and there doesn't seem to be a lifecycle hook for this.

This may just be me misunderstanding what "render" means in this context (if so, I apologize!!) and the setTimeout() workaround fixes my use case, but figured I'd submit and see if it's something to be fixed.

Are you able to attach screenshots, screencasts or a live demo?

[x] Yes (attach) [ ] No

Reproduction Code Pen: https://codepen.io/Dmurl5/pen/wvoejgp?editors=1111

(above pen is a modified version of one posted by artf, original: https://codepen.io/artf/pen/MQpZPj?editors=1111)

Answers (0)

No answers yet.

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...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.