π₯ ResizeObserver Error in React
(Why it appears only in DEV and scares everyone π±)
" Uncaught runtime errors:
ResizeObserver loop completed with undelivered notifications " If you have ever seen this red screen suddenly appear while scrolling, resizing, or editing an AG Grid…
π Welcome to the ResizeObserver Club π
π€ What is ResizeObserver?
ResizeObserver is a browser API that watches:
- Element width changes
- Element height changes
- Layout recalculations
Modern UI libraries like:
- AG Grid
- Material UI
- Ant Design
use ResizeObserver heavily to keep layouts perfect.
AG Grid uses it a LOT π
π What does this error actually mean?
In simple words:
"Hey browser, I tried to recalculate layout again and again…
but UI kept changing continuously π€"
So the browser says:
"Enough! I’m stopping this infinite resize loop." π₯
π§ Real Reasons Why This Happens (AG Grid Edition)
1️⃣ Dynamic height inside CellRenderer
Example:
Height keeps changing → ResizeObserver keeps firing π
2️⃣ autoHeight + long wrapping text
When you combine:
- autoHeight
- white-space: normal
- long text
AG Grid tries to measure height repeatedly.
Result: π₯ ResizeObserver error
3️⃣ Missing getRowId (VERY COMMON)
Without this:
getRowId={(params) => params.data.id}AG Grid thinks:
"One cell changed? Let me re-render EVERYTHING" π
ResizeObserver gets overwhelmed.
4️⃣ Custom dropdowns floating outside grid
When dropdowns are:
- position: absolute
- Rendered outside grid DOM
Scrolling + resize = chaos π₯
π€― Why this happens ONLY in DEV?
This is the most confusing part.
✅ Reason 1: React StrictMode
In DEV mode:
- Components render twice
- Effects run twice
React does this intentionally to catch bugs.
Production build:
π Clean
π Single render
π No red screen
✅ Reason 2: DEV shows runtime overlay
DEV environment shows:
- Warnings as full-screen errors
- ResizeObserver warnings aggressively
Production:
π Console warning only
π UI continues working
✅ Reason 3: Slower DEV rendering
DEV mode is slower.
Slow rendering + heavy DOM = resize timing issues
π ️ Correct Ways to Fix (Production Safe)
✔ Fix 1: Always define getRowId
<AgGridReact
getRowId={(params) => params.data.id}
/>✔ Fix 2: Avoid dynamic height changes
// ✅ Better
<div style={{ minHeight: 32 }}>
<Dropdown hidden={!checked} />
</div>✔ Fix 3: Use AG Grid built-in editors
Instead of custom dropdowns:
cellEditor: 'agSelectCellEditor'AG Grid handles:
- Scroll
- Resize
- Close on blur
✔ Fix 4: Suppress ResizeObserver safely
<AgGridReact
suppressBrowserResizeObserver={true}
stopEditingWhenCellsLoseFocus={true}
/>✔ Officially supported
π Developer Joke (True Story)
"It works in production, so ignore DEV error"
— Famous words before next sprint π
π§ Golden Rules to Avoid This Forever
- ✔ Stable row IDs
- ✔ Avoid height-changing DOM
- ✔ Prefer AG Grid editors
- ✔ Avoid re-setting full rowData
π Wrapping Up
ResizeObserver error is not a bug — it’s a signal.
It tells you:
- Your UI is doing too much resizing
- Your grid needs stability
Fix the cause, not the warning.
π¬ If you faced this issue and fixed it differently, share your experience — someone else is debugging this right now π
Comments
Post a Comment