Update fetch for static page gen, fix DOM patching

This commit is contained in:
2026-07-13 09:51:32 -04:00
parent 9662f83319
commit ea3d2a6d03
10 changed files with 305 additions and 13 deletions

View File

@@ -27,8 +27,11 @@ answers `/api/quotes` with `httputil.RespondGob([]Quote)` and the client decodes
it straight back into `[]Quote` with `httputil.FetchGob` (the same Go type on
both ends — no JSON); and a **user-entered** GitHub repo (`owner/name`) is
fetched with `httputil.FetchJSON` into a tagged Go struct. The client HTTP
transport is `wasmruntime.FetchBytes`, injected once via
`httputil.SetClientTransport`.
transport is `wasmruntime.FetchBytes`, installed by the runtime itself (override
it with `httputil.SetClientTransport` for auth headers or a base URL). `/data` is
a `static` route, and fetching only exists on the client, so the fetches no-op
during SSR: the server pre-renders the page's **spinner**, and the client runs
them for real after hydration.
Styling is **Tailwind**: the dev server (and `build.sh`) run `kjol/cmd/twcss`,
which scans the Go markup + the `webui` kit for utility classes and compiles

View File

@@ -25,7 +25,7 @@ type repoInfo struct {
Stars int `json:"stargazers_count"`
}
//gowasm:page /data layout=app
//gowasm:page /data layout=app static
func DataPage(d Deps) func() *VNode {
// (1) gob from our own server via httputil.RespondGob / FetchGob.
quotes := NewSignal([]Quote{})

View File

@@ -20,6 +20,7 @@ var StaticPaths = map[string]bool{
"/": true,
"/about": true,
"/chart": true,
"/data": true,
}
// RouteLayout maps each route to the name of the layout that wraps it.

View File

@@ -6,17 +6,19 @@ package main
import (
"gowasmweb/app"
"kjol/httputil"
"kjol/vdom"
"kjol/wasmruntime"
)
func main() {
// (The client transport for httputil.FetchGob / FetchJSON needs no wiring —
// importing wasmruntime installs it. On the server it stays nil, so those
// fetches no-op during SSR and the page ships its loading state.)
//
// Collect the signals created during setup so their values can be preserved
// across an in-place hot swap. On a normal load RestoreState is nil (fresh
// state); after a dev hot-reload it carries the previous instance's values,
// which NewSignal restores by creation order.
httputil.SetClientTransport(wasmruntime.FetchBytes) // typed gob/json fetches for app pages
collector := vdom.BeginCollect(wasmruntime.RestoreState())
router := wasmruntime.NewRouter()
deps := app.Deps{Path: router.Path, Navigate: router.Navigate}