diff --git a/templates/rescript-template-xote-ssr/README.md b/templates/rescript-template-xote-ssr/README.md index f55292a..63fbece 100644 --- a/templates/rescript-template-xote-ssr/README.md +++ b/templates/rescript-template-xote-ssr/README.md @@ -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 @@ -17,17 +16,37 @@ A server-rendered starter for [xote](https://github.com/brnrdog/xote) apps. Rend ├── index.html # template with and 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) + + +} +``` + +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. diff --git a/templates/rescript-template-xote-ssr/package.json b/templates/rescript-template-xote-ssr/package.json index ac08f18..316ddad 100644 --- a/templates/rescript-template-xote-ssr/package.json +++ b/templates/rescript-template-xote-ssr/package.json @@ -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" + ] } diff --git a/templates/rescript-template-xote-ssr/rescript.json b/templates/rescript-template-xote-ssr/rescript.json index b8e4091..eab8e4f 100644 --- a/templates/rescript-template-xote-ssr/rescript.json +++ b/templates/rescript-template-xote-ssr/rescript.json @@ -11,7 +11,7 @@ "in-source": true }, "suffix": ".res.mjs", - "dependencies": ["xote", "rescript-signals"], + "dependencies": ["xote"], "jsx": { "version": 4, "module": "XoteJSX" diff --git a/templates/rescript-template-xote-ssr/src/Client.res b/templates/rescript-template-xote-ssr/src/Client.res index b988721..c1ddc03 100644 --- a/templates/rescript-template-xote-ssr/src/Client.res +++ b/templates/rescript-template-xote-ssr/src/Client.res @@ -1,3 +1,3 @@ %%raw(`import "./styles.css"`) -let _ = Hydration.hydrateById(App.view, "root") +Hydration.hydrateById(App.view, "root") diff --git a/templates/rescript-template-xote-ssr/src/Counter.res b/templates/rescript-template-xote-ssr/src/Counter.res index b531e41..2793ee4 100644 --- a/templates/rescript-template-xote-ssr/src/Counter.res +++ b/templates/rescript-template-xote-ssr/src/Counter.res @@ -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) @@ -11,7 +12,11 @@ let make = () => { > {"-"} - + {Signal.get(count)} + {`doubled: ${Signal.get(doubled)->Int.toString}`} } diff --git a/templates/rescript-template-xote-ssr/src/Page.res b/templates/rescript-template-xote-ssr/src/Page.res index ca40051..7bcf7f9 100644 --- a/templates/rescript-template-xote-ssr/src/Page.res +++ b/templates/rescript-template-xote-ssr/src/Page.res @@ -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" >
-

- {"xote · ssr template"} -

+

{"xote · ssr template"}

{"Welcome to xote"}

{"A clean slate for building reactive UIs in ReScript, rendered on the server and hydrated on the client."} @@ -17,8 +15,8 @@ let make = () => {

{"Tech stack"}

diff --git a/templates/rescript-template-xote/README.md b/templates/rescript-template-xote/README.md index 7425d90..d2d9f95 100644 --- a/templates/rescript-template-xote/README.md +++ b/templates/rescript-template-xote/README.md @@ -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 @@ -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
├── 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 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) + + +} +``` + +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 | diff --git a/templates/rescript-template-xote/package.json b/templates/rescript-template-xote/package.json index c9f6659..4589a78 100644 --- a/templates/rescript-template-xote/package.json +++ b/templates/rescript-template-xote/package.json @@ -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" + ] } diff --git a/templates/rescript-template-xote/rescript.json b/templates/rescript-template-xote/rescript.json index 95292b5..ac929f3 100644 --- a/templates/rescript-template-xote/rescript.json +++ b/templates/rescript-template-xote/rescript.json @@ -11,7 +11,7 @@ "in-source": true }, "suffix": ".res.mjs", - "dependencies": ["xote", "rescript-signals"], + "dependencies": ["xote"], "jsx": { "version": 4, "module": "XoteJSX" diff --git a/templates/rescript-template-xote/src/Counter.res b/templates/rescript-template-xote/src/Counter.res index 61b9a29..54437d6 100644 --- a/templates/rescript-template-xote/src/Counter.res +++ b/templates/rescript-template-xote/src/Counter.res @@ -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) @@ -11,13 +12,18 @@ let make = () => { > {"-"} - + {Signal.get(count)} + {`doubled: ${Signal.get(doubled)->Int.toString}`}
} diff --git a/templates/rescript-template-xote/src/Page.res b/templates/rescript-template-xote/src/Page.res index 76f7004..379347a 100644 --- a/templates/rescript-template-xote/src/Page.res +++ b/templates/rescript-template-xote/src/Page.res @@ -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" >
-

- {"xote · csr template"} -

+

{"xote · csr template"}

{"Welcome to xote"}

-

- {"A clean slate for building reactive UIs in ReScript."} -

+

{"A clean slate for building reactive UIs in ReScript."}

{"Tech stack"}

  • {"ReScript v12 — typed language compiling to clean JavaScript"}
  • -
  • {"xote — fine-grained reactivity, no virtual DOM"}
  • -
  • {"Vite 7 — dev server and bundler"}
  • +
  • {"xote 7 — fine-grained reactivity via @xote.component, no virtual DOM"}
  • +
  • {"Vite 8 — dev server and bundler"}
  • {"Tailwind CSS v4 — utility-first, CSS-first config"}