Skip to content

dx: hot reload should preserve scroll position and form state #43

@justrach

Description

@justrach

Problem

Current hot reload does a full location.reload() on file change. This loses:

  • Scroll position
  • Form input values
  • Modal/dropdown state
  • WASM component state

Proposed Solution

Instead of full reload, inject the new HTML via morphdom-style DOM diffing:

  1. Server sends changed HTML over SSE
  2. Client-side diffing patches only the changed nodes
  3. Scroll position, form values, and focus are preserved

Implementation sketch

  • SSE sends the re-rendered page body (not a reload signal)
  • A tiny (~2KB) client-side diff script patches the DOM
  • For WASM components: serialize state before patch, restore after

Complexity

Low-medium. The SSE infrastructure exists. The main work is the DOM diffing logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions