Skip to content
FrontDepth, Home

Component frameworks (Vue, Angular, Svelte) → Server components and islands

2014 – today · 2020 – today

Older era
Newer era
Compare

What changed

Where the state lives

Component frameworks (Vue, Angular, Svelte)

In the component's data(): plain objects and arrays that Vue makes reactive. shown and left are computed, cached until the data they read changes.

Server components and islands

In the island's useState, started from the props the server serialized next to it. The static parts have no state at all.

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.

Server components and islands

The server renders the whole page to HTML; only the island's element is hydrated with hydrateRoot(). React never touches the static HTML.

What happens on a change

Component frameworks (Vue, Angular, Svelte)

Methods and v-model change the data directly (this.todos.push, todo.done); Vue buffers the DOM update until the next tick, a microtask.

Server components and islands

Inside the island a setter re-renders TodoApp and React updates the DOM that differs; the rest of the page never changes.

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.

Server components and islands

Server-only components that never reach the browser, around client islands that each have their own root, script and props.

Why it changed

What hurt in each era along the way, and the era that came next.

  1. 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.

  2. SSR, SSG and meta-frameworks→Hooks

    Pages now arrived rendered, but the components were still classes: one feature's logic was spread over componentDidMount, componentDidUpdate and componentWillUnmount, sharing stateful logic needed higher-order components or render props, and every handler had to be bound to this (see the constructor). Hooks (React 16.8, 2019) gave function components state and effects that can be shared as custom hooks.

    Hydration had its own cost: the browser downloads and runs the code of the whole page, even of parts that never change, and the data travels twice, as HTML and as JSON. Islands and server components later went after that.

  3. Hooks→Server components and islands

    Everything still ran in the browser: the page arrived empty, every component's JavaScript had to download, run and render before anything useful appeared, and server rendering hydrated the whole page even where nothing was interactive. Effects with dependency arrays and stale closures became a common source of bugs. Islands and React Server Components moved the non-interactive parts back to the server.

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)
Server components and islands

Component frameworks (Vue, Angular, Svelte)

Vue 3.5.45

/src/main.js · 41 lines

JavaScript
// 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");

Server components and islands

React 19.3.0, React DOM 19.3.0

/server.jsx · 48 lines

JSX
// Islands era: the server renders the whole page to HTML, and only the islands get JavaScript.
// An islands framework such as Astro does this for you: you only mark what is interactive.
import { renderToStaticMarkup, renderToString } from "react-dom/server";
import TodoApp from "./islands/TodoApp.jsx";

// The "database" lives on the server.
const todos = [
  { id: 1, title: "Read the docs", done: true },
  { id: 2, title: "Write the app", done: false },
];

// A server-only component: it runs here and leaves plain HTML behind. It ships NO JavaScript:
// this file is never sent to the browser, and nothing hydrates its HTML.
function Intro() {
  return (
    <>
      <h1>Todos</h1>
      <p>This heading and note are plain HTML with no JavaScript. Everything below them is an island.</p>
    </>
  );
}

// "<" is escaped so that a todo titled "</script>" cannot end the script element early.
function serialize(props) {
  return JSON.stringify(props).replace(/</g, "\\u003c");
}

export async function handle({ method, path }) {
  if (method !== "GET" || path !== "/") return { status: 404, body: "<h1>Not found</h1>" };
  const props = { initialTodos: todos };

  // Static part: HTML only, without the markers hydration needs. No JavaScript.
  const intro = renderToStaticMarkup(<Intro />);

  // The island: HTML that hydrateRoot can attach to, with its props as JSON right next to it.
  const island = renderToString(<TodoApp {...props} />);

  return {
    status: 200,
    body: `
    <main class="todo-app">
      ${intro}
      <div id="todo-island">${island}</div>
      <script id="todo-island-props" type="application/json">${serialize(props)}</script>
    </main>
    <script src="/client.jsx"></script>`,
  };
}