brust 2.0.0-alpha.5
Guide / Migrating from 0.1.x

Migrating from 0.1.x

brust 2 is a rewrite. 0.1.x lives on the main branch as brustjs; 2.x is @brust/core. Most app code moves over with renamed imports and fewer route fields.

Packages and imports

~/pokedex
$ bun remove brustjs
$ bun add @brust/core
0.1.x2.x
brustjs (binary brustjs)@brust/core (binary brust)
brustjs/routes@brust/core/routes
brustjs/store@brust/core/store, and @brust/core/store/react for useStore
brustjs/client@brust/core/client (the Eden actions client)

Routes

A route has exactly five fields now: path, Component, loader, cache, children. Switch between the two versions of the pokedex's routes:

routes.tsxSwitchPanels · native

The pokedex example on 0.1.x (branch main): every route opts in with native: true.

import { defineRoutes } from 'brustjs/routes'
import AppLayout from './components/AppLayout'
import { browseLoader, detailLoader, homeLoader } from './lib/loaders'
import BrowsePage from './pages/BrowsePage'
import DetailPage from './pages/DetailPage'
import HomePage from './pages/HomePage'

export const routes = defineRoutes([
  {
    Component: AppLayout,
    native: true,
    children: [
      { path: '/', Component: HomePage, native: true, loader: homeLoader },
      { path: '/pokedex', Component: BrowsePage, native: true, loader: browseLoader },
      { path: '/pokemon/{name}', Component: DetailPage, native: true, loader: detailLoader },
    ],
  },
])

Also rejected now: errorBoundary, ssg, middleware, sse, websocket, cache.key and cache.key_ttl_seconds.

CLI

  • brustjs new is now bun create @brust/app.
  • brustjs dev (watch and reload) has no Bun equivalent: brust dev is the Cloudflare loop. Use bun run dev to build and start.
  • --target now means bun or cloudflare, not a native binary platform. --ssg is gone.

What is gone

  • native: true routes and hand-written x-* behaviors: every component is compiled, and x-* attributes are now compiler output.
  • Markdown pages (mdRoutes, mdNav) and static generation.
  • The window.Brust AI runtime.

brust.toml

  • [cache] max_entries and page_max_entries are unknown keys now: [cache] configures a cache adapter.
  • BRUST_AI, BRUST_CACHE_SYNC_URL and BRUST_CACHE_SYNC_CHANNEL are gone. BRUST_ADDR, BRUST_PORT and BRUST_WORKERS mean what they meant.

The actions client

The 0.1.x client was hand-made; the 2.x one is Eden Treaty, and its behavior is not shimmed back:

  • A network failure resolves with status 503, not 0.
  • headers is a Headers object, not a plain record.
  • Path params are encodeURIComponent-ed: item(({ id: "a b/c" })) requests /item/a%20b%2Fc.
Note

Cross-site action requests are rejected by default in 2.x (cross_site = "reject"). Set it to "allow" only if another site must call your actions.