Consider a common scenario in frontend engineering: three senior developers spend four hours tracing a subtle state-synchronization bug through a maze of context providers, custom hooks, and memoization dependency arrays—all inside a lightweight embeddable widget.
When an interactive surface consists of a self-contained widget, a high-frequency data grid, or a third-party SDK script, the weight of a full client-side framework can quickly exceed the complexity of the UI itself, introducing unnecessary bundle parse latency, garbage collection churn, and hydration overhead.
That leads engineering teams to ask a foundational architectural question: When does a surface actually need React, and when is a team better off having migrated from react to vanilla js?
Here is an engineering case study examining why teams transition isolated, performance-critical widgets from react to vanilla javascript, how native browser APIs compare against Virtual DOM reconciliation, and how to evaluate these frontend architectural decisions in system design interviews.

The Framework Trap on Lightweight Surfaces
React is an exceptional architecture for large-scale multi-route applications—including the main totop.app platform shell, where declarative component composition, routing, and complex session views shine.
However, teams run into the "Framework Trap" when they bundle an entire UI runtime into every standalone widget or high-frequency surface by default:
- Pulling in a full Virtual DOM runtime to render a small embeddable widget or high-frequency telemetry panel.
- Adding external state management libraries because deeply nested context providers trigger cascading re-renders.
- Layering
useMemo,useCallback, and custom bailout comparators to prevent Virtual DOM diffing on 60fps streams.
Case Study Benchmark: Embedded Widget in React vs. Vanilla JS
When benchmarking a self-contained interactive widget (such as an embeddable code-runner widget or live telemetry overlay) before and after migrating its hot path to native DOM APIs, the performance profile shifts dramatically across three dimensions:

1. Widget Payload Size: Unbundled Runtime vs. 12KB Native Script
An unoptimized standalone widget that bundles its own framework runtime, UI primitives, and state helpers can easily swell past hundreds of kilobytes (or over 1MB uncompressed).
By contrast, an isolated widget written in zero-dependency Vanilla JavaScript and Web Components compiles down to a single ~12KB (gzipped) module that parses and executes almost instantaneously, even on constrained mobile networks.
2. Interaction to Next Paint (INP) on High-Frequency Updates
When a component receives high-frequency state updates (such as real-time audio waveform meters, live cursor coordinates, or rapid keystroke diffs), routing every tick through declarative state reconciliation forces repeated tree diffing.
Updating targeted DOM nodes or CSS custom properties directly via requestAnimationFrame reduces vanilla js web performance interaction latency from 100ms+ down to single-digit milliseconds.
3. Predictable Imperative Debugging
In declarative frameworks, diagnosing why a component re-rendered—or failed to re-render—requires inspecting hook dependency closures and reference equality. In a small Vanilla JS module, DOM mutations happen explicitly at the call site where .textContent or dataset attributes are updated.
Core Browser Primitives That Replace Framework Boilerplate
Modern browser standards natively solve many of the problems that originally required heavy client libraries:
1. Native Web Components (Custom Elements)
The HTML5 Custom Elements specification provides encapsulated, reusable UI components natively in every modern browser:
class CodeViewer extends HTMLElement {
connectedCallback() {
const code = this.getAttribute('code') || '';
this.innerHTML = `
<div class="code-container">
<pre><code>${this.escapeHTML(code)}</code></pre>
</div>
`;
}
escapeHTML(str) {
return str.replace(/[&<>'"]/g,
tag => ({ '&': '&', '<': '<', '>': '>', "'": ''', '"': '"' }[tag] || tag)
);
}
}
customElements.define('code-viewer', CodeViewer);
2. Lightweight Pub/Sub State Stores
For localized widget state, a 15-line observable store handles subscriptions without external dependencies:
class Store {
constructor(initialState) {
this.state = initialState;
this.listeners = [];
}
subscribe(listener) {
this.listeners.push(listener);
return () => { this.listeners = this.listeners.filter(l => l !== listener); };
}
setState(newState) {
this.state = { ...this.state, ...newState };
this.listeners.forEach(listener => listener(this.state));
}
}
The Trade-offs: Why Full Applications Still Use React
Dropping down to Vanilla JS is a surgical optimization for specific surfaces, not a universal replacement for application frameworks:
- Manual DOM Lifecycle Management: Developers must explicitly manage event listener teardown (
AbortController) and DOM node cleanup to prevent memory leaks. - Architectural Discipline Required: Without component conventions enforced by a framework, large multi-developer codebases can quickly devolve into imperative spaghetti.
- Ecosystem Trade-Offs: Full product applications benefit enormously from React's accessible component primitives, routing, and rich ecosystem.
At totop.app, our interview preparation tracks emphasize mastering underlying browser fundamentals—the DOM event loop, memory management, and rendering pipelines—so you can justify when to use React and when to drop down to native Web APIs.
Architectural Decision Matrix: When to Keep React vs. When to Drop Down to Vanilla JS / Web Components
In senior frontend system design interviews, claiming "React is always too slow" or "Always use React for everything" is a red flag. Principal engineers evaluate the exact runtime constraints of the surface they are building:
| Engineering Dimension | React 19 / Next.js SPA | Vanilla JS + Custom Elements (Web Components) | Hybrid Pattern (React Shell + Imperative Canvas/DOM Core) |
|---|---|---|---|
| Initial JS Payload (Gzip) | ~45 KB – 150 KB+ baseline runtime | 0 KB framework overhead (native browser APIs) | ~45 KB shell, 0 KB overhead in hot loop |
| 60fps / 120fps High-Frequency Mutation | Requires bypassing React state via useRef to avoid VDOM diffing overhead | Native requestAnimationFrame + direct DOM/CSS Custom Property updates | Best of both worlds: React manages chrome/modals; Vanilla JS drives the canvas/grid |
| Third-Party Embeddability | Requires iframe or bundling isolated React root | Native <my-widget> with Shadow DOM style encapsulation | Use Web Components for external SDK embeds |
| Team Velocity & Ecosystem | Massive ecosystem (routing, forms, a11y primitives, SSR) | Requires discipline around manual event cleanup (AbortController) and state sync | High velocity on product pages with surgical optimization on hot paths |
How to Answer "Would You Use React or Vanilla JS for This?" in a System Design Interview
- Quantify the Update Frequency: If state updates happen on human click cadence (1–5 times per second), React's Virtual DOM overhead is negligible (<1ms) and developer velocity wins.
- Isolate the Hot Path: If the prompt involves a 10,000-cell financial order book, a multiplayer cursor canvas, or an embeddable 5 KB analytics snippet, explain how you either build the widget in zero-dependency Vanilla JS / Web Components or isolate the high-frequency loop inside a
ref-backed imperative controller.
Final Thoughts: Choosing the Right Tool for the Surface
Understanding how the web platform works beneath your framework is what separates senior frontend architects from framework operators. When a full application needs rich stateful views and rapid team velocity, React excels; when an embedded widget or 120fps hot loop demands zero runtime overhead, native Vanilla JavaScript and Web Components deliver unmatched efficiency.
Practice Senior React Engineer Questions Live with AI Mock Interviews
Turn any job description across Engineering, DevOps, Data, Marketing, Sales, Finance, or HR into a personalized test and live voice or text AI mock interview on totop.app, or test your speed right now in the 60-Second Senior React Engineer Blitz.
Play 60s Senior React Engineer Blitz (Free, No Login) | Start 14-Day Free Trial | Browse All Interview Guides