Component frameworks (Vue, Angular, Svelte) → SSR, SSG and meta-frameworks
2014 – today · 2016 – today
What changed
- Where the state lives
Component frameworks (Vue, Angular, Svelte)
In the component's
data(): plain objects and arrays that Vue makes reactive.shownandleftarecomputed, cached until the data they read changes.SSR, SSG and meta-frameworks
In the page component's
this.state, started from the props the server loaded withgetInitialProps(); a copy of those props travels with the HTML as JSON.- How the page is rendered
Component frameworks (Vue, Angular, Svelte)
Vue compiles the HTML template (written in the page here) into a render function. When data it read changes, the component re-renders and Vue patches only what differs.
SSR, SSG and meta-frameworks
The server renders the whole page to HTML with
renderToString(); the browser hydrates it withhydrateRoot()and renders every later change itself.- What happens on a change
Component frameworks (Vue, Angular, Svelte)
Methods and
v-modelchange the data directly (this.todos.push,todo.done); Vue buffers the DOM update until the next tick, a microtask.SSR, SSG and meta-frameworks
After hydration everything happens in the browser: a handler calls
this.setState()and React re-renders the page component. Nothing goes back to the server.- How the code is organised
Component frameworks (Vue, Angular, Svelte)
One component object of options (
data,computed,methods) plus its template. Larger apps nest such components into a tree.SSR, SSG and meta-frameworks
A page in
pages/written once for both sides, plus framework code: a server that renders and serializes, and a client entry that hydrates.
Why it changed
What hurt in each era along the way, and the era that came next.
Component frameworks (Vue, Angular, Svelte)→SSR, SSG and meta-frameworks
These apps still rendered in the browser. The server sent an almost empty page, and nothing useful appeared until the framework and the app's JavaScript had downloaded and run; crawlers and link previews that do not run JavaScript saw nothing. Routing, server rendering, code splitting and data loading were left to each team to put together. Meta-frameworks such as Next.js and Nuxt bundled those pieces around the component framework and rendered pages on the server or at build time.
The same app, side by side
The main file of each version. Both apps pass the same test: same markup, same behaviour, different ideas.
The apps run in sandboxes in your browser.
Component frameworks (Vue, Angular, Svelte)
Vue 3.5.45
/src/main.js · 41 lines
// Component-framework era (Vue): the component declares its state, derived values and
// methods; the HTML template in index.html describes the page. Vue keeps the two in sync.
import { createApp } from "vue";
let nextId = 3;
createApp({
// data() returns the state. Vue makes it reactive: while rendering it records which
// properties were read, and any later change to them re-renders the component.
data() {
return {
todos: [
{ id: 1, title: "Read the docs", done: true },
{ id: 2, title: "Write the app", done: false },
],
filter: "all",
title: "",
};
},
// Computed values are cached and re-evaluated only when the data they read changes.
computed: {
shown() {
return this.todos.filter((t) => this.filter === "all" || (this.filter === "done") === t.done);
},
left() {
return this.todos.filter((t) => !t.done).length;
},
},
methods: {
addTodo() {
const title = this.title.trim();
if (!title) return;
// A plain push is enough: no new array, no setState. Vue sees the change itself.
this.todos.push({ id: nextId++, title, done: false });
this.title = "";
},
},
// There is no template option, so mount() uses the HTML inside #app as the template.
}).mount("#app");SSR, SSG and meta-frameworks
React 19.3.0, React DOM 19.3.0
/pages/index.jsx · 101 lines
// A page as Next.js apps wrote it in 2016–2018: a class component with a static data method.
// The same file runs twice: on the server (to HTML) and in the browser (hydration).
import { Component } from "react";
const FILTERS = { all: "All", active: "Active", done: "Done" };
export default class TodoPage extends Component {
// Called on the server before the first render; what it returns becomes the page's props.
// A real page would read a database or an API here.
static async getInitialProps() {
return {
todos: [
{ id: 1, title: "Read the docs", done: true },
{ id: 2, title: "Write the app", done: false },
],
};
}
constructor(props) {
super(props);
// The first state comes only from props, so the server and the browser render the same HTML.
this.state = { todos: props.todos, filter: "all", title: "" };
this.nextId = Math.max(0, ...props.todos.map((t) => t.id)) + 1;
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({ title: event.target.value });
}
handleSubmit(event) {
event.preventDefault();
const title = this.state.title.trim();
if (!title) return;
const todo = { id: this.nextId++, title, done: false };
this.setState((state) => ({ todos: [...state.todos, todo], title: "" }));
}
toggle(id) {
this.setState((state) => ({
todos: state.todos.map((t) => (t.id === id ? { ...t, done: !t.done } : t)),
}));
}
render() {
const { todos, filter, title } = this.state;
const shown = todos.filter((t) => filter === "all" || (filter === "done") === t.done);
const left = todos.filter((t) => !t.done).length;
return (
<main className="todo-app">
<h1>Todos</h1>
<form id="todo-form" onSubmit={this.handleSubmit}>
<input
id="new-todo"
value={title}
onChange={this.handleChange}
placeholder="What needs doing?"
autoComplete="off"
aria-label="New todo"
/>
<button id="add" type="submit">
Add
</button>
</form>
<ul id="todo-list">
{shown.map((todo) => (
<li key={todo.id} className={todo.done ? "done" : undefined}>
<label>
<input
type="checkbox"
data-toggle
checked={todo.done}
onChange={() => this.toggle(todo.id)}
/>{" "}
<span className="title">{todo.title}</span>
</label>
</li>
))}
</ul>
<div className="footer">
<span id="todo-count">{left} left</span>
<div className="filters">
{Object.entries(FILTERS).map(([name, label]) => (
<button
key={name}
type="button"
data-filter={name}
className={filter === name ? "selected" : undefined}
onClick={() => this.setState({ filter: name })}
>
{label}
</button>
))}
</div>
</div>
</main>
);
}
}