跪拜 Guibai
← All articles
Frontend · Vue.js · CSS

Hover Jank: white-space in :hover Forces a Reflow Feedback Loop

By 这可不简单 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Hover animations that touch layout properties like white-space, word-break, font-size, or line-height cause a full reflow every frame, and in grid-aligned lists that reflow spans the entire row. Checking Performance for purple Layout blocks and enabling Layout Shift Regions in DevTools makes the culprit immediately visible, so this class of jank is both diagnosable and preventable with standard patterns.

Summary

A Vue.js project shows a list of cards, each packed with fields (port, packet count, traffic, etc.), and each field reveals a copy icon on hover. When the mouse sweeps across a row, the copy buttons appear with a noticeable delay, even though scrolling and static rendering stay smooth. The developer first suspected the copy button's opacity/visibility transition, but removing it changed nothing. Commenting out two lines in the :hover rule — white-space: normal and word-break: break-word — eliminated the stutter entirely.

The cause sits in the browser's rendering pipeline. white-space and word-break change how text wraps, which directly determines element width and height, so they force a full Layout pass (reflow) and re-measurement of text. By contrast, opacity and visibility only reach Paint or Composite, which are much cheaper. Worse, hover-induced layout changes alter the element's hit-testing area: the cursor slips out, hover cancels, the layout shifts back, and hover re-triggers — a negative feedback loop called hover flicker. The fix is to never change layout-affecting properties in :hover; instead, use absolutely positioned overlays or tooltips that don't participate in document flow.

Takeaways
— white-space and word-break are layout properties; changing them forces a full reflow and text re-measurement, unlike opacity or transform which stay on the compositor.
— The copy button's opacity/visibility transition triggered only Paint, so it was not the source of the jank.
— A hover state that changes layout creates a feedback loop: layout shifts alter hit-testing, the cursor falls out, hover cancels, layout reverts, hover re-triggers — visible as flicker and stutter.
— The practical fix is to avoid layout-affecting properties in :hover and instead show overlays or tooltips using absolute positioning, which keeps them out of the document flow.
— DevTools Performance shows dense purple Layout blocks during hover, and Rendering's Layout Shift Regions highlights the shifted areas, confirming the diagnosis.
— For long lists, virtual scrolling plus content-visibility: auto, and event delegation for many similar interactions, are additional mitigations from the article's checklist.
Conclusions

The cost of a hover effect isn't about the property's name but its trigger stage in the rendering pipeline; white-space looks harmless yet behaves like width or height.

Grid row alignment amplifies a single field's reflow into a whole-row layout change, turning local jank into visible stutter across the list.

The hover feedback loop is a genuine negative feedback cycle: layout and hit-testing mutually influence each other, so the first fix is to break the dependency by removing layout changes from the hover state.

The author's terse 'give it to AI' option, while humorous, implies that LLMs can propose solutions but the developer still needs to understand the rendering pipeline enough to validate them.

Concepts & terms
Hover flicker
A feedback loop where a hover rule changes layout properties, moving the element's box, which shifts the hit-testing target, canceling hover, then re-triggering it as the cursor re-enters, causing repeated reflows and visible jank.
Hit-testing
The browser's process of determining which element lies under the cursor; layout changes from hover can alter the hover target between frames, feeding the flicker loop.
From the discussion
Featured comments
组合搭配函数

The pit of changing layout properties inside :hover is unforgettable once you've stepped on it; the jank appears out of nowhere. Sticking to visibility and opacity is reliable—just pre-fill the size.

这可不简单

Haha yeah, stepped on it once, left a deep impression, that thing.

ashuicoder  → 这可不简单

Haha, AI, you also get it.

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗