Skip to content

Migrating from SolidStart

These tables map SolidStart to Hamur: its files, its routing, its data and server functions, its API routes, its middleware, its environment variables and its config. The tables on pages, data and the server in Migrating from Nuxt apply to any app. The Status column says how close the Hamur way is: same (the name and the behaviour carry over), different (Hamur has the feature under another name or shape; the row says how) and none (Hamur has no equivalent today).

There is no hamur migrate command for SolidStart: the move is by hand, route by route, with the tables below. Keep solid-js. The components stay Solid components; what changes is where the data and the server code live.

The shape is one thing in Hamur: a handler, a typed function that runs on the server, exported from server/index.ts. It replaces "use server", query, action and an API route at once. A load calls it, a component calls it (useAction(fn), useAsyncData(fn, input)), a form posts to it (Form action={fn}), and with a route a URL answers it. It is a public endpoint that must check who calls it.

Step by step

  1. Install Hamur: bun remove @solidjs/start @solidjs/router vinxi, then bun add hamur @hamur/adapter-solid. Keep solid-js.
  2. Write hamur.config.ts with defineConfig({ framework: "solid" }) from app.config.ts (config keys).
  3. Move src/routes/ to app/pages/, src/components/ to app/components/ and src/app.tsx to app/app.tsx (Files and folders).
  4. Turn each query and action into a handler, and each createAsync into a load (Data and server functions).
  5. Move src/routes/api/ to handlers with a route, and src/middleware/ to defineServer (API routes, Middleware).
  6. Run hamur dev, open each page, then hamur build.

Files and folders

SolidStartHamurStatusDifferences
app.config.tshamur.config.tsdifferentwith defineConfig of hamur and framework: "solid"; the keys are below
@solidjs/start and @solidjs/router in package.jsonhamur and @hamur/adapter-soliddifferentbun remove @solidjs/start @solidjs/router vinxi, then bun add hamur @hamur/adapter-solid; see Adapters
src/app.tsxapp/app.tsxdifferentHamur creates the router: the root renders Outlet where Router and FileRoutes were. See Root component
src/entry-server.tsxnonenoneHamur writes the document; meta.document picks a template of app/documents/ for a page. See Page meta
src/entry-client.tsxan app plugindifferentapp/plugins/*.client.ts runs when the app starts in the browser. See Plugins and hooks
src/routes/**app/pages/**sameone file per route; see Files and routes
src/routes/api/**handlers with a route, in server/differentsee API routes
src/middleware/index.tsdefineServer({ middleware }) in server/index.tsdifferentsee Middleware
src/components/**app/components/**sameimport a component by its path. See Co-located components
src/lib/**app/lib/** and server/utils/**differentcode the browser needs under app/, server code under server/utils/
public/public/samecopied into the build as it is. See Directory structure
.env, .env.local.env, .env.local, .env.<mode>differentthe values are the variables of app/env.ts; see Environment variables and Modes

Routing, heading by heading

Each heading of the SolidStart routing page has a row, in its order. {path} is the folders under app/pages/.

SolidStartHamurStatusDifferences
creating a route: routes/about.tsxapp/pages/about.tsxsameindex.tsx is /. See Files and routes
routes/blog/index.tsxapp/pages/blog/index.tsxsame
dynamic routes: routes/users/[id].tsxapp/pages/users/[id].tsxsamethe param is useRoute().params.id where it was useParams()
optional params: routes/users/[[id]].tsxapp/pages/users/[[id]].tsxsame
catch-all routes: routes/[...rest].tsxapp/pages/[...rest].tsxdifferentthe param is a string[], and [...rest] never matches an empty path; [[...rest]] does
the not-found page [...404].tsxapp/pages/[...slug].tsx, or app/pages/_not-found.tsxdifferentit answers 200 unless the page throws createError({ status: 404 }); see A URL no page matches
<HttpStatusCode code={404} />HttpStatusCode from @hamur/adapter-solidsamerenders nothing and sets the status during the server render
nested routes: routes/blog.tsx with routes/blog/app/pages/blog.tsx beside app/pages/blog/differentthe parent renders Outlet where it rendered props.children. See Nested routes
renaming index: a file named for the folderapp/pages/{path}.tsx beside the folderdifferenta folder's own page is index.tsx or the parent page
route groups: routes/(auth)/login.tsxapp/pages/(auth)/login.tsxsamea group adds nothing to the path. See Pathless group layouts
escaping special characters[x+HH], [u+HHHH] and [.] in a file namedifferentsee Escapes
route config: export const routeexport const metadifferentits keys are in the table below
layouts: a parent route with props.childrenapp/layouts/default.tsxdifferenta layout renders children; a page picks another with meta.layout. See Layouts
the A componentLink from @hamur/adapter-soliddifferentto is the path; the active class is router-link-active
useParams()useRoute().paramsdifferentuseRoute from @hamur/adapter-solid
useLocation()useRoute()differentpath, params and query
useNavigate()useRouter().navigate(to, { replace })differentuseRouter from @hamur/adapter-solid; navigateTo(to) also works
useSearchParams()useSearch() from @hamur/adapter-soliddifferenta page declares export const search, a Standard Schema, and reads it with useSearch(). See Search params
useIsRouting()useNavigation().statedifferentidle or loading
useBeforeLeave()onBeforeRouteLeave(fn) from @hamur/adapter-soliddifferentsee Leaving a page
<Navigate href>Navigate from @hamur/adapter-solidsame
redirect("/x") from @solidjs/routerredirect("/x") from hamur/appsamereturn or throw it from a load, route middleware, a request step or a handler
useMatch()useMatches() from @hamur/adapter-soliddifferent
clientOnly(() => import("./x"))ClientOnly from @hamur/adapter-solid, or a x.client.tsx filedifferentsee ClientOnly
<Title>, <Meta>, <Link> of @solidjs/metauseHead from @hamur/adapter-soliddifferentone call for the whole head; see Head

The keys of export const route become the keys of meta:

SolidStartHamurStatusDifferences
route.preloadload in x.load.tsdifferentit runs before the page chunk arrives, and Link runs it on hover and focus. See Data
route.matchFiltersapp/params/{name}.tsdifferenta param is [id=integer] and the matcher is a file with match(param). See Param matchers
export const prerender = true of a routemeta.rules: { prerender: true }differenta route rule for this page's path
the layout of a routemeta.layoutdifferenta name, or false for none

Data and server functions

A server function is a handler. There is no "use server" directive or compiler split: a handler is a module-level defineHandler export of server/index.ts, and the build writes the browser stub.

ts
import { createError, defineHandler } from "hamur/server"
import { schema } from "../../migrate-next/server/schema.ts"

const posts = new Map([["1", { id: "1", title: "Hello" }]])

const idInput = schema<{ id: string }>(
  { type: "object", properties: { id: { type: "string" } }, required: ["id"] },
  (value) => {
    const id = (value as { id?: unknown } | undefined)?.id
    return typeof id === "string" && id
      ? { value: { id } }
      : { issues: [{ message: "An id is required", path: ["id"] }] }
  },
)

const titleInput = schema<{ title: string }>(
  { type: "object", properties: { title: { type: "string" } }, required: ["title"] },
  (value) => {
    const title = (value as { title?: unknown } | undefined)?.title
    return typeof title === "string" && title.trim()
      ? { value: { title: title.trim() } }
      : { issues: [{ message: "A title is required", path: ["title"] }] }
  },
)

export const getPost = defineHandler({
  method: "GET",
  input: idInput,
  handler({ id }) {
    const post = posts.get(id)
    if (!post) throw createError({ status: 404, message: "Post not found" })
    return post
  },
})

export const addPost = defineHandler({
  input: titleInput,
  handler({ title }, { event }) {
    if (!event.context.user) throw createError({ status: 401, message: "Log in first" })
    const post = { id: String(posts.size + 1), title }
    posts.set(post.id, post)
    return post
  },
})

export const health = defineHandler({
  route: "/api/health",
  method: "GET",
  raw: true,
  handler: () => Response.json({ ok: true }),
})

createAsync(() => getPost(id)) is a load that calls the handler. A page reads the value with useData(), which is an accessor in Solid.

ts
import type { Load } from "hamur/app"
import { getPost } from "../../../server/index.ts"

export const load = (async ({ params }) => ({ post: await getPost({ id: params.id as string }) })) satisfies Load
SolidStartHamurStatusDifferences
"use server" in a functiondefineHandler({ handler }) from hamur/serverdifferentexported from server/index.ts; it is a public endpoint. See Defining a handler
query(fn, "posts")defineHandler({ method: "GET", input, handler })differenta GET handler is cacheable; add cache: { maxAge }. See Cache and batches
createAsync(() => getPost(id))useData() of the page's load, or useAsyncData(fn, input)differentboth from @hamur/adapter-solid; the value is an accessor
preload that calls a queryload that calls the handlerdifferentthe handler is the same function the component calls
action(fn, "addPost")defineHandler({ input, handler })differenta POST; the name is the export
useAction(addPost)useAction(fn) from @hamur/adapter-soliddifferentstate, failure, error, pending and run(input)
useSubmission(addPost), useSubmissionsuseAction(fn), useFormStatus()differentpending and result of useAction; useFormStatus is for a child of a form
<form action={addPost} method="post"><Form action={fn}> from @hamur/adapter-soliddifferentworks without JavaScript. See Forms and login
revalidate keys of an actionrefresh(event, getPost, input) in the handler, or useRouter().refresh()differentthe answer carries the value of the read, and the client's next read sends nothing
a thrown redirect() in a server functionreturn redirect(to) from hamur/appsamesee Errors and redirects on the client
getRequestEvent()useEvent() of hamur/server, or ctx.eventdifferentuseEvent() works where no event is passed down; see The request, anywhere
getCookie, setCookie, getHeader, setHeader of vinxi/httpgetCookie, setCookie, getRequestHeader, setHeader of hamur/serverdifferenteach takes the event
useSession of vinxi/httpgetUserSession and setUserSession of @hamur/authdifferentsee Auth and Sessions and security
cache, createResourceuseAsyncData(fn, input)differentthe client cache is meta.staleTime. See The client data cache
a Suspense boundary around createAsyncAwait and useDeferred from @hamur/adapter-soliddifferentsee Deferred values

API routes

An API route is a file of src/routes/api/ that exports GET, POST and the other methods. A handler with a route and raw: true answers a URL: one handler for each method, exported from server/index.ts. The APIEvent is event, and the answer is a Response.

SolidStartHamurStatusDifferences
export function GET(event: APIEvent)defineHandler({ route, method: "GET", raw: true, handler })differentthe second argument has event. See A handler with a route
event.params.idevent.params.idsamethe route uses :id where the file used [id]
event.requestevent.requestsame
json(data) from @solidjs/routerResponse.json(data)differenta plain Response
export const POST with a bodyawait event.request.json() or formData() in a raw handlerdifferentor input of a plain handler, validated
export const ALLnonenonewrite a handler for each method
event.localsevent.contextdifferentsee Middleware

Middleware

createMiddleware({ onRequest, onBeforeResponse }) becomes the middleware list of defineServer. The list runs before every request, in the order written. onBeforeResponse is the code after await next().

ts
import { defineMiddleware, getCookie } from "hamur/server"

export const onRequest = defineMiddleware(({ event }) => {
  event.context.user = getCookie(event, "session") ?? null
})

export const onBeforeResponse = defineMiddleware(async ({ event, next }) => {
  const answer = await next()
  event.response.headers.set("x-served-by", "hamur")
  return answer
})
ts
import { defineServer } from "hamur/server"
import { onBeforeResponse, onRequest } from "./middleware.ts"

export { addPost, getPost, health } from "./posts.ts"

export default defineServer({
  middleware: [onRequest, onBeforeResponse],
})
SolidStartHamurStatusDifferences
createMiddleware({ onRequest })a step of middleware in defineServerdifferentdefineMiddleware(({ event, next }) => …) from hamur/server. See Middleware
onBeforeResponsethe code after await next()differentit sees the answer, sets event.response.headers and may return a Response
onRequest: [a, b]middleware: [a, b]sameoutermost first
event.locals.user = …event.context.user = …differenta handler and a load read it; type the keys with HamurEventContext
a check on the path{ route: "/admin/**", handler }differentthere is no matcher; a list entry with a route runs only under it
return redirect("/login")throw redirect("/login") from hamur/appdifferenta thrown or returned redirect() redirects
a guard of a server functionhandlerMiddleware, or middleware of the handlerdifferenta request step guards the document; the handler's list guards every call. See Handlers: middleware

Environment variables

SolidStartHamurStatusDifferences
process.env.API_KEY on the serverimport { API_KEY } from "#hamur/env/private"differentan entry of defineEnv in app/env.ts; typed, validated at start, never sent to the browser
import.meta.env.VITE_GA_IDimport { GA_ID } from "#hamur/env/public"differentthe entry has public: true; there is no VITE_ prefix. See Environment
import.meta.env.MODE, import.meta.env.DEVimport.meta.env.MODE, import.meta.devdifferentconstants of the build
import.meta.env.SSRimport.meta.serverdifferentimport.meta.client is the other side

Config keys

SolidStartHamurStatusDifferences
server.presetpresetdifferentthe build target is a preset: bun, node, cloudflare, vercel, netlify or static
server.prerender.routesprerender.routessamesee Configuration
ssr: falsea route rule "/**": { ssr: false }, or meta.ssrdifferenta single-page app renders in the browser only. See Rendering modes
middleware: "./src/middleware.ts"server/index.tsdifferentthe default export is defineServer({ middleware })
vitemodules with fromVite(plugin) from @hamur/vite-compatdifferentHamur builds with Bun; a Vite plugin is wrapped. See Vite plugins
server.routeRulesrouteRulessamesee Route rules
extensionsnonenonea page is a file of the adapter's extension, .tsx for Solid

What Hamur lacks

  • entry-server.tsx and entry-client.tsx: the document and the mount are Hamur's. A page that needs its own document uses app/documents/<name>.html; code that runs at start goes in an app plugin.
  • export const ALL in an API route, and a matcher of a middleware list entry: write a handler for each method and use { route, handler }.
  • createResource and cache as separate primitives: useAsyncData and a load cover them.
  • Files that mix a route and its server code in one module: Hamur keeps the page, its load and the handler in separate files, so the build can drop the server code from the browser bundle.