-
Notifications
You must be signed in to change notification settings - Fork 16
Add Xote and Xote SSR templates #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
brnrdog
wants to merge
2
commits into
rescript-lang:master
Choose a base branch
from
brnrdog:brnrdog/xote-templates
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,396
−12
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # xote · SSR template | ||
|
|
||
| A server-rendered starter for [xote](https://github.com/brnrdog/xote) apps. Renders HTML on a Node server, then hydrates on the client so reactivity takes over without re-rendering. | ||
|
|
||
| ## 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 | ||
| - Tailwind CSS v4 (`@tailwindcss/vite`) | ||
|
|
||
| ## Layout | ||
|
|
||
| ``` | ||
| . | ||
| ├── 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 | ||
| ├── package.json | ||
| └── src/ | ||
| ├── styles.css | ||
| ├── Counter.res # uses SSRState.signal so state 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 | ||
| ``` | ||
|
|
||
| ## How it fits together | ||
|
|
||
| 1. `server.mjs` reads `index.html` and (in dev) hands it to Vite for asset/CSS transformation. | ||
| 2. It imports `Server.res` and calls `render()`, which uses `SSR.renderToString(App.view)` to produce HTML and `SSRState.generateScript()` to produce a `<script>` tag carrying initial signal values. | ||
| 3. The placeholders `<!--app-html-->` and `<!--app-state-->` in `index.html` are replaced with those two strings. | ||
| 4. The browser loads `Client.res.mjs`, which calls `Hydration.hydrateById(App.view, "root")`. xote walks the existing DOM, attaches reactive bindings, and reads back the serialized `SSRState` so signals start with the same values the server used. | ||
|
|
||
| ## Scripts | ||
|
|
||
| | Script | What it does | | ||
| | --- | --- | | ||
| | `npm run res:dev` | Watches and compiles ReScript on save. Run during development. | | ||
| | `npm run res:build` | One-shot ReScript build. | | ||
| | `npm run res:clean` | Removes ReScript build artifacts. | | ||
| | `npm run dev` | Runs `node server.mjs` with Vite in middleware mode. | | ||
| | `npm run build` | Builds the client bundle and the SSR bundle. | | ||
| | `npm run build:client` | Just the client bundle (`dist/client/`). | | ||
| | `npm run build:ssr` | Just the SSR bundle (`dist/server/Server.res.js`). | | ||
| | `npm run start` | Runs the server in production mode against the built bundles. | | ||
|
|
||
| ## Develop | ||
|
|
||
| ```bash | ||
| npm install | ||
| npm run res:dev | ||
| # in another terminal: | ||
| npm run dev | ||
| ``` | ||
|
|
||
| Open http://localhost:3000. The page is server-rendered (view source — the counter HTML is already there) and becomes interactive after hydration. | ||
|
|
||
| ## Build & run in production | ||
|
|
||
| ```bash | ||
| npm run res:build | ||
| npm run build | ||
| npm run start | ||
| ``` | ||
|
|
||
| `server.mjs` defaults to port 3000; override with `PORT=8080 npm run start`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| node_modules | ||
| dist | ||
| lib | ||
| *.res.mjs | ||
| *.res.js | ||
| .DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>xote · SSR template</title> | ||
| <link rel="stylesheet" href="/src/styles.css" /> | ||
| </head> | ||
| <body> | ||
| <div id="root"><!--app-html--></div> | ||
| <!--app-state--> | ||
| <script type="module" src="/src/Client.res.mjs"></script> | ||
| </body> | ||
| </html> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A new optional prompt for a stack variant, let me know if you'd prefer a more flat structure as we have now. Just aiming to keep the first selection cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could eventually do the same for the react ones