Question presented to candidate:
"We need to show an audit log with 50,000 entries in a scrollable panel. Rendering it with a plain v-for freezes the page. How would you render it efficiently in Vue? Explain virtual scrolling and what you would build or use."
What a strong answer should cover:
- Why plain
v-foris slow: every row is a component or element to create, lay out and keep in memory; keys and diffing do not remove browser layout cost. - Virtual scrolling (windowing): render only the rows in view plus an overscan buffer, use a spacer with the full height so the scrollbar is right, and position the slice with a transform.
- The maths for fixed heights:
start = floor(scrollTop / rowHeight) - overscan,end = ceil((scrollTop + viewport) / rowHeight) + overscan. - Variable heights: estimate, measure rendered rows, and correct offsets (what libraries such as TanStack Virtual handle).
- Supporting choices:
shallowReffor the data, stable keys, passive scroll listeners, and alternatives such as pagination or infinite loading. - Trade-offs: browser find-in-page and accessibility only see rendered rows; sticky headers and scroll restoration need care.
Clarifying questions expected:
- "Are rows fixed height or variable?"
- "Do users need to search the page with Ctrl+F or select across many rows?"
Code / implementation expected: Yes β a minimal fixed-height virtual list or the setup of a library.