Skip to content

Conversation

@erikgaas
Copy link
Contributor

@erikgaas erikgaas commented Jan 4, 2026

Summary

Fixes #817 — Live reload enters infinite page reload loop on uvicorn >= 0.39.

The Problem

The /live-reload WebSocket handler was returning immediately after accept(). In uvicorn 0.39+, this correctly sends a close frame, which triggers the client's reconnect logic and causes an infinite reload loop.

The Fix

Keep the WebSocket handler alive by looping on receive() until the client disconnects.

Testing

  • Reproduced the bug with uvicorn 0.40 and fast_app(live=True)
  • Confirmed the fix stops the infinite reload loop
  • Page now loads and stays stable

Keep WebSocket handler alive by waiting on receive() instead of
returning immediately after accept(). Fixes #817.
@gitnotebooks
Copy link

gitnotebooks bot commented Jan 4, 2026

Review these changes at https://app.gitnotebooks.com/AnswerDotAI/fasthtml/pull/818

async def live_reload_ws(websocket):
await websocket.accept()
try:
while True: await websocket.receive()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equivalent to just saying "wait forever until we get a disconnect". This appears to be idiomatic for websockets.

@erikgaas erikgaas requested a review from jph00 January 4, 2026 02:18
@jph00 jph00 merged commit a93bad9 into main Jan 4, 2026
2 checks passed
@jph00 jph00 deleted the fix-live-reload-817 branch January 4, 2026 04:37
@jph00
Copy link
Contributor

jph00 commented Jan 4, 2026

Thanks @erikgaas :)

@jph00 jph00 added the bug Something isn't working label Jan 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Live reload enters infinite page reload loop on uvicorn >= 0.39

3 participants