Table of contents

Heading components register themselves in the this context while they render. The table of contents, rendered after them, reads the list.

The runtime renders siblings in order, so the table of contents, placed after the article, is only rendered once all headings have registered, even those from async components: one section of the article is "loaded from a CMS" with a delay. The article still streams right away, and a skeleton holds the place of the table of contents until it arrives.

The article uses <H2> and <H3> components for its headings. If you'd rather keep plain <h2> and <h3> tags, you can intercept the JSX and register them while they render.

A short introduction to Jeasx: what it is, how routes and components work, and how to get started.

What is Jeasx?

Jeasx is a server-side rendering framework for Node.js and Bun. You write pages and API endpoints as async JSX functions, and Jeasx renders them on the server and streams the HTML to the browser. It is built on Fastify, jsx-async-runtime, and esbuild or Bun as bundler.

Routes

Routing comes from your file structure: every file in src whose name is in brackets is a route.

Pages and endpoints

src/blog/[index].jsx answers /blog, and src/blog/[feed].jsx answers /blog/feed. A route returns JSX for an HTML page, or any other payload, like JSON for an API.

Guards

A [...guard].js runs before all routes in its folder and below. It can check a login, load data for the routes, or answer the request itself, like with a redirect.

Components

Components are plain functions that return JSX, with a few extras on the server.

Async components

A component can be async and simply await its data: a database query, an API call or a file. No hooks or loaders needed.

The this context

All components of a request share one this object. Put the request, the current user or settings on it, and every component can read them without passing props down.

Streaming

The HTML is sent while it renders. The browser shows the top of the page while slow parts further down are still loading.

In the browser

Most pages need little JavaScript. When they do, use what you like: plain scripts, HTMX, Alpine, or islands built with React, Vue or Svelte.

Scripts and styles

An index.js or index.css next to your routes is bundled for the browser, so each page loads only the code it needs.

Getting started

  • npm run dev starts the development server, which rebuilds on every change.
  • npm run build bundles the app for production.
  • npm start runs the built app.