Deleting JS Dependencies: A CSS Migration Playbook

Deleting JS Dependencies: A CSS Migration Playbook

The process spine for retiring a UI library: what it actually does for you, the coverage verdicts that stop features vanishing, parity before deletion, and when it stays.

Replacing a positioning, carousel, accordion, select, or animation library with CSS primitives is a migration, and migrations fail in predictable places — an unnoticed feature the library was quietly handling, two implementations running at once, a deletion that shipped before anyone checked keyboard behavior. This is the process spine: inventory what the dependency actually does for you, map each used feature to a primitive with an honest coverage verdict, build the CSS path behind a gate, verify visual, behavioral, and accessibility parity, account the savings with real numbers, and treat keeping the library as a legitimate outcome rather than a failure.

Inventory what the dependency actually does

The migration target is not the library. It is the fraction of the library your components actually use, and that fraction can be far smaller than the API surface — which is good news, because it means the work is bounded, and it is only good news if you enumerate it rather than assume it.

Start from the call sites, not the documentation. Grep for the imports, list the options passed at each one, and write down the resulting set of behaviors: this component uses collision detection and flip, that one uses arrow positioning, three of them use only basic placement. What you want at the end is a concrete list of behaviors in use, not a count of components.

Then look for the inventory nobody remembers choosing. Mature UI libraries can carry edge-case handling that is on by default or built into how the library behaves, so it is easy to miss in your call sites: repositioning inside a scrolling ancestor rather than the viewport, mirroring for right-to-left layouts, recalculating under page zoom, coping with a virtual keyboard shrinking the visual viewport on mobile, cleaning up listeners when a component unmounts mid-animation. These are the features that make a migration look finished and then produce a bug report from one locale or one device class. They belong on the list, marked as behaviors you are inheriting responsibility for.

Measure the weight honestly while you are here. The number that matters is the dependency's real contribution to the bundle your users download after tree-shaking, on the routes that actually load it — not the package's advertised size, and not the unpacked size on disk. Note its upgrade history too: a dependency that has forced a breaking migration twice in three years carries a maintenance cost that does not show up in kilobytes at all.

Map features to primitives

With the used-feature list in hand, the mapping is mechanical. Each feature gets a primitive and a verdict, and the verdict is the whole point — it forces the partial cases into the open instead of letting them evaporate. In the illustrative mapping below, the Partial verdicts and the Decision column are one project's calls, not general verdicts.

Used featureCSS primitiveCoverageDecision
Basic placement relative to triggerAnchor positioningFullMigrate
Flip on collisionPosition-try fallbacksFullMigrate
Arrow pointing at triggerAnchor positioningPartialRe-own in component CSS
Reposition inside scroll containerAnchor positioningPartialVerify per layout, descope one usage
Positioning against a virtual reference (cursor or text selection)NoneUncoveredKeep small JavaScript
Focus trapping while openModal dialog (showModal())PartialMigrate; re-own Tab cycling in component code

The three verdicts do different work. Full means the primitive does what the library did, and the per-feature articles on this topic supply the mechanics. Partial means the primitive covers the common case but not your case, and it needs an explicit decision: re-own the gap in a small amount of your own code, deliberately descope the behavior because it turns out nobody needs it, or let this one feature keep the library alive. Uncovered means there is no primitive, and pretending otherwise is how features silently disappear from a product.

One more input belongs in the table before it becomes a plan: the support state of each primitive, verified and dated at the moment you check. A primitive that is broadly interoperable makes this a replacement. A primitive that ships in one engine makes it an enhancement layered over the library, which is a different project with a different payoff — you do not get to delete anything yet, and pretending you will is how a migration stalls half-finished.

Build in parallel behind a gate

The CSS implementation should grow alongside the JavaScript one inside the same component, with something deciding which renders: a build flag, a component variant, or a feature-query boundary. Nobody has to be brave, and nothing is deleted while it is still the only implementation.

The rule that keeps this phase from breeding bugs is one mechanism per browser. Where the primitive is supported, the JavaScript path must be fully off — not merely visually overridden, not left running with its output ignored. Double-implementation is a source of migration bugs, and they are hard to debug: the library is still positioning an element that CSS is also positioning, the two disagree by a few pixels under some scroll condition, and the symptom looks like a rendering bug rather than the architectural mistake it is. The library's listeners are still attached, so its side effects still fire. Half the point of the migration is not paying for the JavaScript at runtime, and a path that is off but present pays for itself in full.

Scope discipline does the rest. Migrate one component, or one usage tier, at a time. A design system converted in a single change is hard to review, can only be reverted as a whole, and produces a regression window that cannot be bisected. The first component you convert is also where you discover which of your coverage verdicts were optimistic, which is a much cheaper lesson at one component than at thirty.

Verify parity before deleting

Parity has three dimensions, and each fails in its own way.

Visual parity is the easy one: compare the two implementations across states — default, open, hovered, focused, at the narrow and wide ends of the layout, in both text directions if you support them. Screenshot comparison is the natural fit here; naming the verification is what matters, and the tooling has its own literature.

Behavioral parity is where the hidden inventory comes due, and it is best written as an explicit checklist derived from the list you built in the first step. Does keyboard interaction still work, including the keys the library bound that nobody documented? Is focus order preserved, and does focus return where it should on close? Does dismissal still happen on every path — Escape, outside click, route change? Does it survive a resize, a scroll of an ancestor container, a zoom to 200 percent?

Accessibility parity deserves to be checked rather than assumed. The native primitive can be the better choice, because the semantics are the engine's job rather than yours — but not always, and a mature library sometimes papers over a gap the primitive still leaves open in one engine. Verify the specifics you rely on with an actual screen reader rather than by reading the specification.

Then keep the old path revertible for a release cycle. Deletion is the last step, not the first: ship the CSS implementation, let it run in production under real traffic and real devices, and remove the dependency in a separate change once nothing has come back. A migration that deletes and ships in one commit has no cheap way to undo when the bug report arrives on a Sunday.

Account the savings honestly

Measure before and after on the affected routes, with the same build configuration, and count the transitive dependencies the deletion frees — those are often larger than the direct one. That is the number to report, because it is the number that is true.

What you should not report is a projection. Savings are entirely project-specific: they depend on how much of the library was tree-shaken away already, how many routes loaded it, and what else in the bundle depended on it. Published examples are useful as existence proofs rather than as forecasts — Chrome's Google I/O 2025 recap describes Pinterest, an early adopter of CSS carousels, cutting roughly 2,000 lines of JavaScript to roughly 200 lines of CSS (Chrome for Developers, accessed August 2026). That is a real result from a specific codebase, and it says nothing about yours until you measure. Reducing shipped JavaScript is a well-understood performance lever (web.dev, accessed August 2026); how much of it you get here is an empirical question.

The second-order gains are real and should be stated as expectations rather than guarantees: fewer upgrade cycles to absorb, less positioning jank because layout stays on the engine's own timeline, and accessibility semantics maintained by browser vendors instead of by your dependency's maintainers.

And the ledger has a cost side, which honest accounting includes. Writing and reviewing fallbacks takes time. Parity testing takes time, and it is easy to underestimate. Features you re-owned from the partial column are now yours to maintain, including the edge cases the library had already found. A migration can pay for itself without paying for itself immediately, and saying so protects the credibility of the migrations that do pay for themselves.

When the library stays

Keeping the dependency is a legitimate outcome of this process, and a playbook that can only produce one answer is not a decision procedure.

The stay-decisions worth respecting are specific. Your browser floor includes engines without the primitive, and the fallback is not acceptable for this component — a menu that lands in the wrong place is not a designed degraded state. Features in the uncovered column are heavily used, and re-owning them would recreate a meaningful fraction of the library with none of its maturity. Or the component is scheduled for redesign anyway, which makes migrating the current version pure waste.

A stay is a dated decision, not a permanent one. Record what would change it — a named primitive reaching the support level you need, a specific feature gaining coverage, the redesign shipping — and when to look again. Without that record, "we evaluated this" decays into "we do not know why we still have this" within two engineer rotations.

Deletion is per-dependency engineering judgment, and that is the point of running the process rather than arguing about it.

Project Inquiry