Skip to content

Reload code in place instead of restarting the server - #37

Open
afomera wants to merge 1 commit into
mainfrom
internal-code-reloading
Open

Reload code in place instead of restarting the server#37
afomera wants to merge 1 commit into
mainfrom
internal-code-reloading

Conversation

@afomera

@afomera afomera commented Aug 20, 2026

Copy link
Copy Markdown
Member

Reloading ran through Guard, which restarted the whole Puma process on every file change. Hanami can now reload in place via Hanami::Slice#reload!, so the server stays up.

hanami server wraps the app in a Rack middleware that checks for changed files once per request and reloads before dispatching, so a reload only happens when there is something to serve and never lands mid-edit. The middleware has to sit outside Hanami.app, since a reload replaces its middleware stack: Server subclasses Hanami::CLI::Server to reach the app between the rack config file being read and the server starting, inheriting its option mapping and choice of rack server. A reload that raises is not committed, so the next request retries once the file is fixed.

Guard and guard-puma are no longer needed, and hanami install now removes the Guardfile it used to generate.

Depends on hanami/hanami#1625, once that is merged I can remove the gemfile update!

Reloading ran through Guard, which restarted the whole Puma process on every
file change. Hanami can now reload in place via `Hanami::Slice#reload!`, so
the server stays up.

`hanami server` wraps the app in a Rack middleware that checks for changed
files once per request and reloads before dispatching, so a reload only
happens when there is something to serve and never lands mid-edit. The
middleware has to sit outside `Hanami.app`, since a reload replaces its
middleware stack: `Server` subclasses `Hanami::CLI::Server` to reach the app
between the rack config file being read and the server starting, inheriting
its option mapping and choice of rack server. A reload that raises is not
committed, so the next request retries once the file is fixed.

Guard and guard-puma are no longer needed, and `hanami install` now removes
the Guardfile it used to generate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant