Custom component view onRender is called early
Thanks for reporting this, @Dmurl5. The issue with Custom component view onRender is called early appears to be a race condition or state management timing problem. This typically happens when component lifecycle events and DOM modifications overlap, creating an inconsistent state. What to try: Add a setTimeout wrappe...
Read full answer below ↓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 (1)
Thanks for reporting this, @Dmurl5.
The issue with Custom component view onRender is called early appears to be a race condition or state management timing problem. This typically happens when component lifecycle events and DOM modifications overlap, creating an inconsistent state.
What to try:
- Add a setTimeout wrapper to ensure the DOM has settled:
setTimeout(() => {
// your operation here
}, 0);
-
Check initialization order — make sure components are fully loaded before you interact with them
-
Use the editor's event system — listen to completion events:
editor.on('component:mount', (component) => {
// safe to interact with component here
});
Recommended next steps:
- Test with the latest GrapesJS version if you haven't
- Provide a minimal reproducible example (CodeSandbox) — this helps the team identify the root cause faster
- Include GrapesJS version, browser, and console errors in your report
Related Questions and Answers
Continue research with similar issue discussions.
Issue #6269
Component model and view inits every time it's dragged over every component present in Canvas on which it can be dropped into
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Version 130.0.6723.59 (Official Bui...
Issue #4247
Components disappearing/not being rendered at cloning, moving or adding
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chromium v96 Reproducible demo link https:...
Issue #5705
Component tools misalign when the editor is resized
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v122 Reproducible demo link https:/...
Issue #5280
Event handler on view not bound to the component
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Version 115.0.5790.114 Reproducible...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →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.
Tutorial
GrapesJS vs Webflow vs Builder.io vs Puck: Which Visual Builder to Choose in 2026
A practitioner's 2026 comparison of GrapesJS, Webflow, Builder.io, and Puck — pricing, AI features, lock-in, and a one-line rule for picking the right one
Tutorial
Find the Right GrapesJS Plugin in Seconds: Smarter Discovery Is Live
We're shipping a set of discovery upgrades. New label filters, a proper compatibility switch for GrapesJS vs Studio, one-click and a smarter sort bar.
Tutorial
Why use grapesjs shadcn for your template builder
Skip months of editor plumbing and start with a fully working visual builder — polished UI included.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.