DEV Community

rYOUcerious
rYOUcerious

Posted on

Cerious-Scroll: Why I Built Yet Another Virtual Scroller

Why I Built Yet Another Virtual Scroller

I know what you’re thinking.

The web already has a million virtual scrolling libraries. Why build another one?

Honestly, I wasn’t trying to.

For years I’ve worked on enterprise applications that deal with large amounts of data. Grids, reports, dashboards, tables, trees… the usual stuff. Every time virtual scrolling came into the picture, things would start out great until the requirements became real.

Need variable row heights? Things get complicated.

Need rows to dynamically resize? More complexity.

Need to prepend data at the top? Good luck.

Need to preserve position while content is loading, expanding, collapsing, filtering, or changing size? That’s where things really start getting interesting.

The more I dug into virtual scrolling implementations, the more I noticed that most of them seemed to be fighting the same battle.

Not rendering.

Scrolling.

That’s what eventually led me to build Cerious-Scroll.

The Problem I Kept Running Into

Most virtual scrollers think in terms of pixels.

The scrollbar position becomes the source of truth.

That sounds reasonable until the content starts changing underneath you.

Imagine you’re reading row 500,000 in a dataset.

Now an image above loads.

Or a row expands.

Or 50 new records get inserted at the top.

Suddenly the thing you’re looking at isn’t where it used to be.

Now the virtualizer has to figure out how to compensate.

How much height changed?

How much should the spacer change?

Should the viewport move?

Should the scrollbar move?

Should neither move?

A lot of virtualization bugs come from trying to answer those questions after the fact.

I Started Looking At The Problem Differently

Instead of treating the scrollbar position as the source of truth, I started treating the viewport itself as the source of truth.

In other words:

The user doesn’t care what pixel they’re at.

They care about what they’re looking at.

That sounds like a small distinction, but it completely changes how the problem is approached.

Once the viewport becomes the thing you’re preserving, operations like inserts, removals, height changes, filtering, and prepending become much easier to reason about.

Instead of trying to keep a pixel position stable, you’re trying to keep the user’s view stable.

That’s the foundation Cerious-Scroll was built on.

The Goal Was Never “Render Millions Of Rows”

That’s actually the easiest part.

Rendering a million rows isn’t impressive if the experience falls apart when the data changes.

What I wanted was something that could handle the annoying stuff:

  • Variable heights
  • Dynamic content
  • Images loading later
  • Expandable rows
  • Inserts
  • Removals
  • Prepends
  • Arbitrary jumps
  • Large datasets

Without losing its place.

Without visual jumps.

Without needing special handling for every scenario.

Why It Works With More Than Just Lists

One thing I intentionally avoided was tying the engine to a specific UI pattern.

I didn’t want a “table virtualizer.”

I didn’t want a “list virtualizer.”

I wanted a scrolling engine.

The engine doesn’t really care whether it’s rendering:

  • A feed
  • A table
  • Cards
  • Nested content
  • Arbitrary DOM

As long as it can measure content and manage the viewport, the same scrolling model applies.

That’s why the same core engine now powers vanilla JavaScript, Angular, React, and Vue wrappers.

The scrolling logic lives in one place.

The framework wrappers are just wrappers.

What Surprised Me

The most surprising thing wasn’t performance.

It was how many virtual scrolling issues disappear when you stop treating the scrollbar as the thing you’re preserving.

Once I started preserving viewport state instead, a lot of the edge cases that normally require special handling started becoming natural outcomes of the model.

That’s when I realized I might actually be onto something different.

Not just another virtual scroller.

A different way of thinking about scrolling itself.

Final Thoughts

I’m not claiming Cerious-Scroll is the answer to every virtualization problem.

But after building grids, dashboards, reporting tools, and enterprise applications for years, I became convinced that rendering was never the hard part.

Maintaining a stable viewport is.

Everything in Cerious-Scroll was built around that idea.

The result just happens to be a virtual scroller that can handle some pretty ridiculous datasets along the way.

Github: https://github.com/ceriousdevtech/cerious-scroll

Demos: https://ceriousdevtech.github.io/cerious-scroll/

Top comments (0)