Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions templates/rescript-template-xote-ssr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ A server-rendered starter for [xote](https://github.com/brnrdog/xote) apps. Rend
## Stack

- ReScript v12 (JSX transform: `XoteJSX`)
- xote ^6.2 — uses `SSR.renderToString`, `SSRState`, and `Hydration`
- rescript-signals
- Vite 7 — runs in middleware mode for dev, and produces both client and SSR bundles for production
- xote ^7.2 — uses `SSR.renderToString`, `SSRState`, and `Hydration`
- Vite 8 — runs in middleware mode for dev, and produces both client and SSR bundles for production
- Tailwind CSS v4 (`@tailwindcss/vite`)

## Layout
Expand All @@ -17,17 +16,37 @@ A server-rendered starter for [xote](https://github.com/brnrdog/xote) apps. Rend
├── index.html # template with <!--app-html--> and <!--app-state--> placeholders
├── server.mjs # Node HTTP server (Vite middleware in dev, static + SSR in prod)
├── vite.config.mjs
├── rescript.json
├── rescript.json # JSX v4 + XoteJSX module, xote PPX, -open Xote
├── package.json
└── src/
├── styles.css
├── Counter.res # uses SSRState.signal so state survives hydration
├── Counter.res # @xote.component; SSRState.signal survives hydration
├── Page.res # landing page composition
├── App.res # shared `view` thunk used by server and client
├── Server.res # exports render() → { html, stateScript }
└── Client.res # imports styles, calls Hydration.hydrateById
```

## Writing components

Components use the `@xote.component` annotation, enabled by `"ppx-flags": ["xote/ppx/ppx"]` in `rescript.json`. It derives props like `@jsx.component` and makes the returned JSX fine-grained: read signals inline and only the attribute or text that reads them updates.

```rescript
@xote.component
let make = (~label: string) => {
let count = Signal.make(0)
<button onClick={_ => Signal.update(count, n => n + 1)}>
{`${label}: `}
{Signal.get(count)}
</button>
}
```

Bare `{…}` children (strings, numbers, signal reads, nodes) render directly — no `View.text` needed. A signal read hidden behind a function from another module, or hoisted into a `let`, is read once; wrap it in a thunk (`{() => Store.total(store)}`) to keep it reactive. See the [xote docs](https://xote.dev/) for more.

The PPX ships as a prebuilt binary installed by xote's `postinstall` script. `package.json` already allows that script for pnpm (`pnpm.onlyBuiltDependencies`) and bun (`trustedDependencies`); if your package manager skipped it, run `node node_modules/xote/ppx/postinstall.js` once.

## How it fits together

1. `server.mjs` reads `index.html` and (in dev) hands it to Vite for asset/CSS transformation.
Expand Down
18 changes: 13 additions & 5 deletions templates/rescript-template-xote-ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@
"build:ssr": "vite build --ssr src/Server.res.mjs --outDir dist/server"
},
"dependencies": {
"xote": "^7.1.0"
"xote": "^7.2.0"
},
"devDependencies": {
"@tailwindcss/vite": "^4.0.0",
"tailwindcss": "^4.0.0",
"vite": "^7.0.0"
}
"@tailwindcss/vite": "^4.3.5",
"tailwindcss": "^4.3.5",
"vite": "^8.3.8"
},
"pnpm": {
"onlyBuiltDependencies": [
"xote"
]
},
"trustedDependencies": [
"xote"
]
}
2 changes: 1 addition & 1 deletion templates/rescript-template-xote-ssr/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"in-source": true
},
"suffix": ".res.mjs",
"dependencies": ["xote", "rescript-signals"],
"dependencies": ["xote"],
"jsx": {
"version": 4,
"module": "XoteJSX"
Expand Down
2 changes: 1 addition & 1 deletion templates/rescript-template-xote-ssr/src/Client.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
%%raw(`import "./styles.css"`)

let _ = Hydration.hydrateById(App.view, "root")
Hydration.hydrateById(App.view, "root")
8 changes: 7 additions & 1 deletion templates/rescript-template-xote-ssr/src/Counter.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@xote.component
let make = () => {
let count = SSRState.signal("count", 0, SSRState.Codec.int)
let doubled = Computed.make(() => Signal.get(count) * 2)

let decrement = (_: Dom.event) => Signal.update(count, n => n - 1)
let increment = (_: Dom.event) => Signal.update(count, n => n + 1)
Expand All @@ -11,13 +12,18 @@ let make = () => {
>
{"-"}
</button>
<span class="font-mono text-xl tabular-nums">
<span
class={Signal.get(count) < 0
? "font-mono text-xl tabular-nums text-red-600"
: "font-mono text-xl tabular-nums"}
>
{Signal.get(count)}
</span>
<button
class="px-3 py-1 rounded bg-slate-900 text-white hover:bg-slate-700" onClick={increment}
>
{"+"}
</button>
<span class="text-sm text-slate-500"> {`doubled: ${Signal.get(doubled)->Int.toString}`} </span>
</div>
}
8 changes: 3 additions & 5 deletions templates/rescript-template-xote-ssr/src/Page.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ let make = () => {
class="max-w-2xl w-full bg-white rounded-2xl shadow-sm border border-slate-200 p-8 space-y-8"
>
<header class="space-y-2">
<p class="text-xs uppercase tracking-widest text-slate-500">
{"xote · ssr template"}
</p>
<p class="text-xs uppercase tracking-widest text-slate-500"> {"xote · ssr template"} </p>
<h1 class="text-3xl font-semibold"> {"Welcome to xote"} </h1>
<p class="text-slate-600">
{"A clean slate for building reactive UIs in ReScript, rendered on the server and hydrated on the client."}
Expand All @@ -17,8 +15,8 @@ let make = () => {
<h2 class="text-sm font-medium text-slate-700"> {"Tech stack"} </h2>
<ul class="text-sm text-slate-600 space-y-1 list-disc pl-5">
<li> {"ReScript v12 — typed language compiling to clean JavaScript"} </li>
<li> {"xote — fine-grained reactivity with SSR + hydration"} </li>
<li> {"Vite 7 — dev server (middleware mode) and bundler"} </li>
<li> {"xote 7 — fine-grained reactivity with SSR + hydration"} </li>
<li> {"Vite 8 — dev server (middleware mode) and bundler"} </li>
<li> {"Tailwind CSS v4 — utility-first, CSS-first config"} </li>
</ul>
</section>
Expand Down
28 changes: 24 additions & 4 deletions templates/rescript-template-xote/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ A client-only starter for [xote](https://github.com/brnrdog/xote) apps. Renders
## Stack

- ReScript v12 (JSX transform: `XoteJSX`)
- xote ^6.2 + rescript-signals
- Vite 7
- xote ^7.2
- Vite 8
- Tailwind CSS v4 (`@tailwindcss/vite`)

## Layout
Expand All @@ -15,15 +15,35 @@ A client-only starter for [xote](https://github.com/brnrdog/xote) apps. Renders
.
├── index.html # mounts /src/Main.res.mjs into <div id="app">
├── vite.config.mjs # registers @tailwindcss/vite
├── rescript.json # JSX v4 + XoteJSX module, -open Xote
├── rescript.json # JSX v4 + XoteJSX module, xote PPX, -open Xote
├── package.json
└── src/
├── styles.css # @import "tailwindcss";
├── Counter.res # reactive counter (Signal-based)
├── Counter.res # reactive counter (@xote.component, Signal + Computed)
├── Page.res # landing page composition
└── Main.res # imports styles, mounts <Page /> into "app"
```

## Writing components

Components use the `@xote.component` annotation, enabled by `"ppx-flags": ["xote/ppx/ppx"]` in `rescript.json`. It derives props like `@jsx.component` and makes the returned JSX fine-grained: read signals inline and only the attribute or text that reads them updates.

```rescript
@xote.component
let make = (~label: string) => {
let count = Signal.make(0)
<button onClick={_ => Signal.update(count, n => n + 1)}>
{`${label}: `}
{Signal.get(count)}
</button>
}
```

Bare `{…}` children (strings, numbers, signal reads, nodes) render directly — no `View.text` needed. A signal read hidden behind a function from another module, or hoisted into a `let`, is read once; wrap it in a thunk (`{() => Store.total(store)}`) to keep it reactive. See the [xote docs](https://xote.dev/) for more.

The PPX ships as a prebuilt binary installed by xote's `postinstall` script. `package.json` already allows that script for pnpm (`pnpm.onlyBuiltDependencies`) and bun (`trustedDependencies`); if your package manager skipped it, run `node node_modules/xote/ppx/postinstall.js` once.

## Scripts

| Script | What it does |
Expand Down
18 changes: 13 additions & 5 deletions templates/rescript-template-xote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@
"preview": "vite preview"
},
"dependencies": {
"xote": "^7.1.0"
"xote": "^7.2.0"
},
"devDependencies": {
"@tailwindcss/vite": "^4.0.0",
"tailwindcss": "^4.0.0",
"vite": "^7.0.0"
}
"@tailwindcss/vite": "^4.3.5",
"tailwindcss": "^4.3.5",
"vite": "^8.3.8"
},
"pnpm": {
"onlyBuiltDependencies": [
"xote"
]
},
"trustedDependencies": [
"xote"
]
}
2 changes: 1 addition & 1 deletion templates/rescript-template-xote/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"in-source": true
},
"suffix": ".res.mjs",
"dependencies": ["xote", "rescript-signals"],
"dependencies": ["xote"],
"jsx": {
"version": 4,
"module": "XoteJSX"
Expand Down
10 changes: 8 additions & 2 deletions templates/rescript-template-xote/src/Counter.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@xote.component
let make = () => {
let count = Signal.make(0)
let doubled = Computed.make(() => Signal.get(count) * 2)

let decrement = (_: Dom.event) => Signal.update(count, n => n - 1)
let increment = (_: Dom.event) => Signal.update(count, n => n + 1)
Expand All @@ -11,13 +12,18 @@ let make = () => {
>
{"-"}
</button>
<span class="font-mono text-xl tabular-nums">
<span
class={Signal.get(count) < 0
? "font-mono text-xl tabular-nums text-red-600"
: "font-mono text-xl tabular-nums"}
>
{Signal.get(count)}
</span>
<button
class="px-3 py-1 rounded bg-slate-900 text-white hover:bg-slate-700" onClick={increment}
>
{("+")}
{"+"}
</button>
<span class="text-sm text-slate-500"> {`doubled: ${Signal.get(doubled)->Int.toString}`} </span>
</div>
}
12 changes: 4 additions & 8 deletions templates/rescript-template-xote/src/Page.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@ let make = () => {
class="max-w-2xl w-full bg-white rounded-2xl shadow-sm border border-slate-200 p-8 space-y-8"
>
<header class="space-y-2">
<p class="text-xs uppercase tracking-widest text-slate-500">
{"xote · csr template"}
</p>
<p class="text-xs uppercase tracking-widest text-slate-500"> {"xote · csr template"} </p>
<h1 class="text-3xl font-semibold"> {"Welcome to xote"} </h1>
<p class="text-slate-600">
{"A clean slate for building reactive UIs in ReScript."}
</p>
<p class="text-slate-600"> {"A clean slate for building reactive UIs in ReScript."} </p>
</header>
<section class="space-y-2">
<h2 class="text-sm font-medium text-slate-700"> {"Tech stack"} </h2>
<ul class="text-sm text-slate-600 space-y-1 list-disc pl-5">
<li> {"ReScript v12 — typed language compiling to clean JavaScript"} </li>
<li> {"xote — fine-grained reactivity, no virtual DOM"} </li>
<li> {"Vite 7 — dev server and bundler"} </li>
<li> {"xote 7 — fine-grained reactivity via @xote.component, no virtual DOM"} </li>
<li> {"Vite 8 — dev server and bundler"} </li>
<li> {"Tailwind CSS v4 — utility-first, CSS-first config"} </li>
</ul>
</section>
Expand Down
Loading