Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion fasthtml/live_reload.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from starlette.routing import WebSocketRoute
from starlette.websockets import WebSocketDisconnect
from fasthtml.basics import FastHTML, Script

__all__ = ["FastHTMLWithLiveReload"]
Expand All @@ -23,7 +24,11 @@ def LiveReloadJs(reload_attempts:int=20, reload_interval:int=1000, **kwargs):
"""
return Script(src % (reload_attempts, reload_interval))

async def live_reload_ws(websocket): await websocket.accept()
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.

except WebSocketDisconnect: pass

class FastHTMLWithLiveReload(FastHTML):
"""
Expand Down