Stepper persistence: use def-store instead of broken cookies
The home stepper's step-idx signal was not persisting across SX navigation because set-cookie/freeze-to-sx wasn't working in the WASM kernel. Replace with def-store which uses a global registry that survives island re-hydration. Also fix sx_http.exe build: add sx_http back to dune, inline scope primitives (Sx_scope module was removed), add declarative form stubs and render stubs, fix /sx/ home route mapping. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
~home/stepper
|
||||
()
|
||||
(let
|
||||
((source "(div (~cssx/tw :tokens \"text-center\")\n (h1 (~cssx/tw :tokens \"text-3xl font-bold mb-2\")\n (span (~cssx/tw :tokens \"text-rose-500\") \"the \")\n (span (~cssx/tw :tokens \"text-amber-500\") \"joy \")\n (span (~cssx/tw :tokens \"text-emerald-500\") \"of \")\n (span (~cssx/tw :tokens \"text-violet-600 text-4xl\") \"sx\")))")
|
||||
((source (first (sx-parse "(div (~cssx/tw :tokens \"text-center\")\n (h1 (~cssx/tw :tokens \"text-3xl font-bold mb-2\")\n (span (~cssx/tw :tokens \"text-rose-500\") \"the \")\n (span (~cssx/tw :tokens \"text-amber-500\") \"joy \")\n (span (~cssx/tw :tokens \"text-emerald-500\") \"of \")\n (span (~cssx/tw :tokens \"text-violet-600 text-4xl\") \"sx\")))")))
|
||||
(store
|
||||
(if (client?) (def-store "home-stepper" (fn () {:step-idx (signal 9)})) nil))
|
||||
(steps (signal (list)))
|
||||
(step-idx (signal 9))
|
||||
(step-idx (if store (get store "step-idx") (signal 9)))
|
||||
(dom-stack-sig (signal (list)))
|
||||
(code-tokens (signal (list))))
|
||||
(letrec
|
||||
@@ -264,17 +266,7 @@
|
||||
((target (- (deref step-idx) 1)))
|
||||
(rebuild-preview target)
|
||||
(reset! step-idx target)
|
||||
(update-code-highlight)
|
||||
(set-cookie "sx-home-stepper" (freeze-to-sx "home-stepper")))))))
|
||||
(freeze-scope "home-stepper" (fn () (freeze-signal "step" step-idx)))
|
||||
(let
|
||||
((saved (get-cookie "sx-home-stepper")))
|
||||
(when
|
||||
saved
|
||||
(thaw-from-sx saved)
|
||||
(when
|
||||
(or (< (deref step-idx) 0) (> (deref step-idx) 16))
|
||||
(reset! step-idx 9))))
|
||||
(update-code-highlight))))))
|
||||
(let
|
||||
((parsed (sx-parse source)))
|
||||
(when
|
||||
@@ -320,10 +312,7 @@
|
||||
(div
|
||||
:class "flex items-center justify-center gap-2 md:gap-3"
|
||||
(button
|
||||
:on-click (fn
|
||||
(e)
|
||||
(do-back)
|
||||
(set-cookie "sx-home-stepper" (freeze-to-sx "home-stepper")))
|
||||
:on-click (fn (e) (do-back))
|
||||
:class (str
|
||||
"px-2 py-1 rounded text-3xl "
|
||||
(if
|
||||
@@ -337,10 +326,7 @@
|
||||
" / "
|
||||
(len (deref steps)))
|
||||
(button
|
||||
:on-click (fn
|
||||
(e)
|
||||
(do-step)
|
||||
(set-cookie "sx-home-stepper" (freeze-to-sx "home-stepper")))
|
||||
:on-click (fn (e) (do-step))
|
||||
:class (str
|
||||
"px-2 py-1 rounded text-3xl "
|
||||
(if
|
||||
|
||||
Reference in New Issue
Block a user