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:

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.
Issue #3939
BUG: Disabled drag and drop in preview
GrapesJS version[X] I confirm to use the latest version of GrapesJSWhat browser are you using? v95Reproducible demo link https://codesandbo...
Issue #4754
BUG: Closing `</script>` tag not escaped for script properties
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Version 107.0.5304.122 (64-bit) Rep...
Issue #4006
Background color automatically changes to black
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link https://grap...
Issue #2972
FEAT: Disable scripts on canvas
Hello, first of all thanks for a great tool. On my project i hit the problem where I need to disable scripts inside the editor. I found 2 s...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.