While scrolling a page, Chrome's console prints `[Violation] Forced reflow while executing JavaScript took 47ms`. What is that warning telling you about your code, and what would you do with it?
answer
- a browser advisory, not an error
- Chrome only, no stack attached
- symptom without a location
- measurement happened mid-script
- next stop is the trace
basics
~20 sChrome prints that when your JavaScript asked the browser for a geometry value and forced it to compute layout on the spot, costing 47ms inside that script. It is a symptom, not a location: record a performance trace of the same interaction to find the call site.
solid answer
~50 sIt is a Chrome performance advisory, not an error — nothing threw, and other browsers will not print it. Chrome emits it when a script asks for a value the browser can only answer by running layout right then, and that forced layout takes longer than an internal threshold. The number is how much of that script's time went into layout it was pushed into, which on a scroll frame is enough to drop frames on its own. What it does **not** give you is a stack, an element, or a line number, so the next step is to reproduce the interaction while recording a performance trace and look for the scripting entry with repeated layout work underneath it. Then judge it by where it lands: on a scroll or interaction path it is worth fixing; once during startup it is usually noise.
go deeper
Know that Violation lines are Chrome's own performance warnings, not exceptions, and be able to say that the page measured something and made the browser compute layout mid-script. Say plainly that the next step is a performance recording.
Explain why the figure is a lower bound on the real cost, why repeated console lines under-count the occurrences, and how you get from the message to a call site in a trace rather than guessing at handlers.
Show triage judgment: decide whether the forced layout sits on a scroll or interaction path or in one-off startup work, and insist the fix is verified by re-recording the trace, not by the warning disappearing.
Own the policy question. Decide whether browser advisories belong in a team's signal set at all, given that they are Chrome-only and hardware-dependent, and what field measurement you would rely on instead when setting a bar the whole organisation is held to.
## What the message actually is `[Violation] …` lines are Chrome's own performance advisories. They are printed by the browser, not by your code, they are warnings rather than errors, and nothing in the page failed when one appears. Chrome has a family of them — a long-running task, a `'scroll'` handler that took too long, a non-passive listener added to a scroll-blocking event — and *forced reflow* is the one that fires when a script made the browser run layout synchronously and that work exceeded an internal time threshold. Firefox and Safari do not emit this message at all, so its absence in another browser is not evidence that the problem is gone. ## Why the browser was forced Some DOM properties cannot be answered from whatever the browser last computed. If your script has changed the DOM or its styles since the last layout, and then asks for a geometry value — `offsetHeight`, `getBoundingClientRect()`, `scrollTop`, certain `getComputedStyle()` values — the browser has to bring layout up to date before it can return a number. That is the "forced" part: layout that would normally have happened once, at the browser's convenience before the next paint, happened in the middle of your function instead. One such read is cheap when nothing is pending. The expensive shape is a loop that writes something, reads a geometry value, writes again, reads again — every read pays for the write before it. ## What the number means, and what it hides The milliseconds in the message are the time the browser spent doing forced layout work while that script was running. That is a *lower bound* on the damage, not the total: the script's own work, style recalculation, and the paint that follows are all on top of it. A 47ms figure on a 60Hz display has already blown roughly three frames' worth of budget by itself. Chrome also collapses repeats, so a handler firing on every scroll event may print far fewer lines than the number of times it actually forced layout — never read the count of console lines as the frequency of the problem. ## What the warning does not tell you It names no function, no file, no element and no stack. That is the whole reason triage does not stop here. Two candidates can look at the same line and reach opposite conclusions, because the warning is equally consistent with your own scroll handler, a measurement inside a UI library, and a third-party widget measuring its own container. ## Turning it into a fix The reliable path is: reproduce the interaction while recording a performance trace, find the scripting entry that covers it, and look for layout work repeated many times inside a single call rather than once at the end. DevTools flags forced layouts and can point at the JavaScript that triggered them, which gives you the call site the console message withheld. Only then do you change code — and the shape of the fix is either to stop interleaving reads with writes, or to stop measuring at all and let an observer tell you what changed. Afterwards, re-record: the proof is that the repeated layout entries collapse to one per frame, not that the console line stopped appearing. ## When it is fine to leave alone Prioritise by where it lands. A forced reflow inside a scroll frame or inside a click handler is user-visible — it delays the next paint and shows up in interaction latency. The same 47ms once during application bootstrap, off any interaction path, is usually worth a note and nothing more. Silencing the message by filtering the console is the one response that is always wrong: it removes the only free signal you had while leaving the frame cost exactly where it was.
- Would wrapping the offending handler in a setTimeout make that violation go away?It may stop the message, because the work is now spread across tasks and each chunk may fall under Chrome's threshold, but the layout cost is unchanged — the same reads still force the same layouts, now in a later task. That is hiding the signal rather than fixing the frame. The genuine fixes are to stop interleaving reads and writes, or to stop measuring and let an observer report the change instead.
- You see this warning only on one engineer's machine and never in CI. Does that make it a non-issue?No — it makes the threshold machine-dependent, not the problem. The violation fires on absolute milliseconds, so a slower laptop crosses it while a fast desktop does not, even though both run the same number of forced layouts. Real users skew slower than developer hardware, so treat the warning as confirmation on a slow machine and use a trace, plus field data, to decide whether it matters.
saying these in an interview costs you the question
- Calls it a JavaScript error that broke something
- Assumes the message points at the exact slow line
- Says it means the CSS selectors are too complex
- Suggests filtering the console to make it stop
- Claims a browser upgrade will fix it