[Issue #9] Hot reload for development #19

Merged
HugoNijhuis merged 2 commits from issue-9-hot-reload into main 2026-01-09 16:34:16 +00:00
Owner

Summary

Add automatic rebuild and browser reload functionality for development. When Go source files change, the WASM binary is automatically rebuilt and connected browsers reload to show the updated application.

Changes

  • Watcher (watcher.go): File system watcher using polling to detect changes in Go source files
  • Builder (builder.go): Executes WASM compilation when files change
  • LiveReload (livereload.go): WebSocket server for browser-to-server communication
  • Inject (inject.go): Injects reload script into HTML responses
  • DevServer (devserver.go): Combines all components into an easy-to-use development server
  • Updated README.md with hot reload documentation

Usage

dev := host.NewDevServer("public", "index.html", ".", "public/app.wasm")
dev.ListenAndServe(":8080")

Closes #9

## Summary Add automatic rebuild and browser reload functionality for development. When Go source files change, the WASM binary is automatically rebuilt and connected browsers reload to show the updated application. ## Changes - **Watcher** (`watcher.go`): File system watcher using polling to detect changes in Go source files - **Builder** (`builder.go`): Executes WASM compilation when files change - **LiveReload** (`livereload.go`): WebSocket server for browser-to-server communication - **Inject** (`inject.go`): Injects reload script into HTML responses - **DevServer** (`devserver.go`): Combines all components into an easy-to-use development server - Updated `README.md` with hot reload documentation ## Usage ```go dev := host.NewDevServer("public", "index.html", ".", "public/app.wasm") dev.ListenAndServe(":8080") ``` Closes #9
HugoNijhuis added 1 commit 2026-01-09 16:03:41 +00:00
Add hot reload for development
All checks were successful
CI / build (pull_request) Successful in 32s
62f085e8e6
Implement automatic rebuild and browser reload during development:

- File watcher monitors .go files for changes with configurable extensions
- Builder compiles Go source to WASM on file changes
- LiveReload WebSocket server notifies connected browsers to reload
- DevServer combines all components for easy development setup
- HTML injection adds reload script automatically

Usage:
  dev := host.NewDevServer("public", "index.html", ".", "public/app.wasm")
  dev.ListenAndServe(":8080")

Closes #9

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Author
Owner

Code Review

Summary

Excellent feature addition implementing automatic rebuild and browser reload for development. Well-architected with clean component separation.

Highlights

  • Clean separation: Watcher, Builder, LiveReload, Inject, DevServer
  • Good API design with functional options pattern
  • Proper concurrency handling (mutexes, WaitGroups)
  • Custom minimal WebSocket implementation (no external deps)
  • Good test coverage (392 lines of tests)
  • Comprehensive README documentation

Issue: Unused Code

host/devserver.go lines 461-473 - The responseWriter struct is defined but never used:

// ResponseWriter wraps http.ResponseWriter to capture the response
type responseWriter struct {
    http.ResponseWriter
    buf        *bytes.Buffer
    statusCode int
}

func (rw *responseWriter) WriteHeader(code int) {
    rw.statusCode = code
}

func (rw *responseWriter) Write(b []byte) (int, error) {
    return rw.buf.Write(b)
}

Please remove this unused code before merging.

Minor Notes

  • Error handling in readLoop silently ignores errors (acceptable for reload-only use)
  • WebSocket is intentionally minimal - appropriate for this use case
## Code Review ### Summary Excellent feature addition implementing automatic rebuild and browser reload for development. Well-architected with clean component separation. ### Highlights - Clean separation: Watcher, Builder, LiveReload, Inject, DevServer - Good API design with functional options pattern - Proper concurrency handling (mutexes, WaitGroups) - Custom minimal WebSocket implementation (no external deps) - Good test coverage (392 lines of tests) - Comprehensive README documentation ### Issue: Unused Code **host/devserver.go lines 461-473** - The `responseWriter` struct is defined but never used: ```go // ResponseWriter wraps http.ResponseWriter to capture the response type responseWriter struct { http.ResponseWriter buf *bytes.Buffer statusCode int } func (rw *responseWriter) WriteHeader(code int) { rw.statusCode = code } func (rw *responseWriter) Write(b []byte) (int, error) { return rw.buf.Write(b) } ``` Please remove this unused code before merging. ### Minor Notes - Error handling in readLoop silently ignores errors (acceptable for reload-only use) - WebSocket is intentionally minimal - appropriate for this use case
HugoNijhuis added 1 commit 2026-01-09 16:23:19 +00:00
Remove unused responseWriter struct
All checks were successful
CI / build (pull_request) Successful in 27s
341379c166
Address review feedback to remove dead code.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Author
Owner

Code Review - Approved

Excellent hot reload feature with clean architecture and good test coverage.

Highlights

  • Clean separation: Watcher, Builder, LiveReload, Inject, DevServer
  • Functional options pattern for configuration
  • Proper concurrency handling (mutexes, WaitGroups)
  • Custom minimal WebSocket implementation (no external deps)
  • Good test coverage (392 lines across 3 test files)
  • Comprehensive README documentation

Previous Feedback

Unused responseWriter struct removed.

LGTM - merging.

## Code Review - Approved Excellent hot reload feature with clean architecture and good test coverage. ### Highlights - Clean separation: Watcher, Builder, LiveReload, Inject, DevServer - Functional options pattern for configuration - Proper concurrency handling (mutexes, WaitGroups) - Custom minimal WebSocket implementation (no external deps) - Good test coverage (392 lines across 3 test files) - Comprehensive README documentation ### Previous Feedback Unused `responseWriter` struct removed. LGTM - merging.
HugoNijhuis merged commit 7393778453 into main 2026-01-09 16:34:16 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: flowmade-one/iris#19