Frontend School

Virtualized Trip History Feed with Dynamic Item Heights

Machine Coding
hard

Virtualized Trip History Feed with Dynamic Item Heights

Hard
Virtualized List
Performance
React
Frontend
Dynamic Height

Virtualized Trip History Feed with Dynamic Item Heights

Overview

Uber users often have extensive trip histories. Displaying thousands of past trips efficiently is crucial for a smooth user experience, especially on mobile devices or in web browsers. This problem challenges you to build a high-performance virtualized list component capable of rendering a large dataset of trip records, where each trip item can have a dynamically varying height based on its content.

What you need to do / Task

Your primary task is to implement a VirtualizedList React component that can efficiently render a long list of Trip items. The list must meet the following requirements:

  1. Core Virtualization: Only render the items currently visible in the viewport, plus a small buffer of items above and below, to minimize DOM elements.
  2. Dynamic Item Heights: Each TripItem component will have a height that varies based on the length of its details content. Your VirtualizedList must correctly measure and account for these dynamic heights to maintain accurate scroll positions and offsets.
  3. Smooth Scrolling: Ensure the scrolling experience is fluid and responsive, even with thousands of items in the dataset.
  4. Scroll Position Integrity: As the user scrolls, the content should not jump or flicker due to incorrect height calculations or re-renders.

UI/UX expectations

  • The VirtualizedList should be contained within a fixed-height scrollable container.
  • Each TripItem should clearly display its driverName, pickupLocation, dropoffLocation, fare, and details.
  • The layout of individual trip items is basic; focus on functional correctness and performance over elaborate styling.
  • No interactive elements (e.g., buttons, forms) within TripItem are required.

Acceptance criteria

  • The VirtualizedList component renders only a subset of the total items at any given time.
  • Scrolling through the list reveals new items and removes old ones from the DOM.
  • The scrollbar accurately reflects the total height of all items, even those not rendered.
  • The position of items within the scrollable area is correct, regardless of their varying heights.
  • Scrolling is smooth and performant, without noticeable lag or jank, for a dataset of 10,000+ items.
  • The component handles changes in container height (e.g., browser window resize) gracefully, adjusting visible items and scroll logic accordingly.

Constraints

Constraints & assumptions

  • Data Size: The list will contain 10,000+ trip items. The provided mock data generator will create 10,000 items.
  • Item Height Variation: Individual TripItem components will have dynamic heights, ranging approximately from 50px to 200px based on content.
  • Environment: React functional components with Hooks. Modern browser environment.
  • Container: The VirtualizedList will be rendered inside a fixed-height div (e.g., 600px).
  • No External Libraries: Do not use third-party virtualization libraries (e.g., react-window, react-virtualized). The solution must be implemented from scratch.

Out of scope

  • Accessibility (beyond basic semantic HTML).
  • Advanced filtering, sorting, or search functionalities.
  • Real-time data updates (focus on initial render and scrolling).
  • Complex styling or animations.

What interviewers evaluate

  • Correctness of Virtualization Logic: Ensures only visible items are rendered and positioned accurately.
  • Handling Dynamic Heights: Demonstrates a robust approach to measuring and accounting for variable item heights.
  • Performance and Efficiency: Achieves smooth scrolling and minimizes unnecessary computations and re-renders.
  • Code Structure and Maintainability: Reflects good architectural design, readability, and adherence to React best practices.

Loading editor...