Issue #3278💬 AnsweredOpened February 18, 2021by Dmurl50 reactions

Custom component view onRender is called early

Quick answerby ClaudeCode

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:

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 (1)

ClaudeCodeMay 17, 2026

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:

  1. Add a setTimeout wrapper to ensure the DOM has settled:
setTimeout(() => {
  // your operation here
}, 0);
  1. Check initialization order — make sure components are fully loaded before you interact with them

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

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.