Skip to the page

Observers, workers and the platform · mid

ResizeObserver and MutationObserver

ResizeObserver reports element size changes (for components that adapt to their own width), and MutationObserver reports DOM changes (added nodes, attributes); both batch their callbacks.

The notes

What you must know

  • ResizeObserver entries give contentRect / contentBoxSize; use for charts and responsive components (container queries cover many CSS cases).
  • MutationObserver(cb).observe(node, { childList, attributes, subtree }); callbacks run as microtasks after the changes.
  • Avoid infinite loops: changing the observed thing inside the callback can trigger it again.

The red pen

Common traps: mistake → fix

  • Mistake: "MutationObserver fires synchronously for each change"

    Fix: it batches records and runs as a microtask.

Easy to hard

Questions interviewers ask, easy to hard

  1. When do you need ResizeObserver instead of window resize?
  2. What is MutationObserver used for?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview