Fix hydration flash: skip initial effect run when state matches SSR
Root cause: the stepper's rebuild effect (update-code-highlight, rebuild-preview) fired immediately on hydration via schedule-idle, modifying the DOM after replaceChildren swapped in identical content. This caused a visible text change after the initial frame. Fix: track initial step-idx value and first-run flag. Skip the effect on first run if the current step matches the SSR state (from cookie). The effect only fires on actual user interaction. Result: SSR and hydrated text content are identical. replaceChildren swaps DOM nodes but the visual content doesn't change. Zero flash. Test: "No clobber: clean" — 0 text changes during hydration. All 8 home features pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -345,7 +345,7 @@
|
||||
(build-code-tokens (first parsed) tokens step-ref 0)
|
||||
(reset! code-tokens tokens)))))
|
||||
(let
|
||||
((_eff (effect (fn () (schedule-idle (fn () (build-code-dom) (rebuild-preview (deref step-idx)) (update-code-highlight) (run-post-render-hooks)))))))
|
||||
((_eff (let ((initial-idx (deref step-idx)) (first-run (signal true))) (effect (fn () (let ((cur (deref step-idx))) (if (and (deref first-run) (= cur initial-idx)) (reset! first-run false) (do (reset! first-run false) (schedule-idle (fn () (build-code-dom) (rebuild-preview cur) (update-code-highlight) (run-post-render-hooks)))))))))))
|
||||
(div
|
||||
(~tw :tokens "space-y-4 text-center")
|
||||
(div
|
||||
|
||||
Reference in New Issue
Block a user