AnswerDotAI / fasthtml

The fastest way to create an HTML app
https://fastht.ml/
Apache License 2.0
5.66k stars 237 forks source link

[BUG] Hot reload not working on Windows Vs Code #573

Open dorianherle opened 2 weeks ago

dorianherle commented 2 weeks ago

I am new to FastHtml and wnted to try out the live=True, hot reload option. my code

from fasthtml import common as fh

app, rt = fh.fast_app(live=True)

@rt ('/')
def get():
    return fh.Div(fh.P("Hello"))

fh.serve()

When I run it I get:

Link: http://localhost:5001 INFO: Will watch for changes in these directories: ['C:\Users\dhh\Downloads\floorplan\floorplanv2'] INFO: Uvicorn running on http://0.0.0.0:5001 (Press CTRL+C to quit) INFO: Started reloader process [34124] using WatchFiles INFO: Started server process [44776] INFO: Waiting for application startup. INFO: Application startup complete.

Now when I change this line: return fh.Div(fh.P("Hello World"))

It does not automatically quickly change the sentence on my browser but it does

WARNING: WatchFiles detected changes in 'cleanroom\main.py'. Reloading... INFO: Shutting down INFO: Waiting for application shutdown. INFO: Application shutdown complete. INFO: Finished server process [44776] INFO: Started server process [30376] INFO: Waiting for application startup. INFO: Application startup complete.

And I need to refresh the page. I am using Chrome, but I have tried with other browsers, same story. Also tried to run the code from the Anaconda Terminal direclty, same story.

paryska99 commented 1 week ago

Same setup, same problem here

tilman151 commented 1 week ago

I tried the setup (Windows + VSCode) and do not run into problems.

@dorianherle could you check the network activity in the developer console of your browser (press F12). There you should see a web socket connection that does the live reloading. Maybe it is getting blocked by the Windows firewall (PyCharm added some firewall exception for me).

TransparentIA commented 4 days ago

Hi @dorianherle, I once had a similar problem with these warnings:

WARNING:  Unsupported upgrade request.
WARNING:  No supported WebSocket library detected. Please use "pip install 'uvicorn[standard]'", or install 'websockets' or 'wsproto' manually.
INFO:     127.0.0.1:53315 - "GET /live-reload HTTP/1.1" 404 Not Found

After I installed websockets, the issue has disappeared and live reloading works again:

INFO:     127.0.0.1:53520 - "GET / HTTP/1.1" 200 OK
INFO:     ('127.0.0.1', 53523) - "WebSocket /live-reload" [accepted]
INFO:     connection open
WARNING:  StatReload detected changes in '\fasthtml\fast_html_examples\untitled2.py'. Reloading...
INFO:     Shutting down

Hope this helps.