reflex-dev / reflex

🕸️ Web apps in pure Python 🐍
https://reflex.dev
Apache License 2.0
19.24k stars 1.09k forks source link

[REF-1842] `reflex run` hanging/lag when open localhost in browser #2510

Closed gunungpw closed 6 months ago

gunungpw commented 7 months ago

Describe the bug A clear and concise description of what the bug is. reflex run does not respond when live-reload and sometimes lagging when open localhost is browser

To Reproduce Steps to reproduce the behavior:

Expected behavior A clear and concise description of what you expected to happen. Reflex running "fine" when live-reloading

Screenshots If applicable, add screenshots to help explain your problem.

Specifics (please complete the following information):

Additional context Add any other context about the problem here.

`reflex run --loglevel debug` ~\Projects\werna-web via  v3.12.0 (.venv) ❯ reflex run --loglevel debug ``` ────────────────────────────────── System Info ────────────────────────────────── Debug: Config file: 'C:\\Users\\Acer\\Projects\\werna-web\\.venv\\Lib\\site-packages\\reflex\\config. py' Debug: Config: app_name='werna_web' loglevel= frontend_port=3000 frontend_path='' backend_port=8000 api_url='http://localhost:8000' deploy_url='http://localhost:3000' backend_host='0.0.0.0' db_url='sqlite:///reflex.db' redis_url=None telemetry_enabled=True bun_path='C:\\Users\\Acer\\AppData\\Local\\reflex\\bun\\bin\\bun' cors_allowed_origins=['*'] tailwind={} timeout=120 next_compression=True event_namespace=None frontend_packages=[] cp_backend_url='https://rxcp-prod-control-plane.fly.dev' cp_web_url='https://control-plane.reflex.run' gunicorn_worker_class='uvicorn.workers.UvicornH11Worker' Debug: Running command: ['C:\\Users\\Acer\\AppData\\Local\\reflex\\fnm\\node-versions\\v18.17.0\\installa tion\\node.exe', '-v'] Debug: Running command: ['C:\\Users\\Acer\\AppData\\Local\\reflex\\fnm\\fnm.exe', '--version'] Debug: [Reflex 0.3.10a2 with Python 3.12.0 (PATH: C:\Users\Acer\Projects\werna-web\.venv\Scripts\python.exe)] Debug: [Node 18.17.0 (Expected: 18.17.0) (PATH:C:\Users\Acer\AppData\Local\reflex\fnm\node-versions\v18.17.0\installation\ node.exe)] Debug: [FNM 1.35.1 (Expected: 1.35.1) (PATH: C:\Users\Acer\AppData\Local\reflex\fnm\fnm.exe)] Debug: [OS Windows 10.0.22621] Debug: Using package installer at: C:\Users\Acer\AppData\Local\reflex\fnm\node-versions\v18.17.0\installation\npm Debug: Using package executer at: C:\Users\Acer\AppData\Local\reflex\fnm\node-versions\v18.17.0\installation\npm Warning: Windows Subsystem for Linux (WSL) is recommended for improving initial install times. ────────────────────────────── Starting Reflex App ────────────────────────────── Compiling: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 15/15 0:00:00 Debug: Running command: ['C:\\Users\\Acer\\AppData\\Local\\reflex\\fnm\\node-versions\\v18.17.0\\installa tion\\npm', 'run', 'next', 'telemetry', 'disable'] Debug: Running command: ['C:\\Users\\Acer\\AppData\\Local\\reflex\\fnm\\node-versions\\v18.17.0\\installa tion\\node.exe', '-v'] ────────────────────────────────── App Running ────────────────────────────────── Debug: Running command: ['C:\\Users\\Acer\\AppData\\Local\\reflex\\fnm\\node-versions\\v18.17.0\\installa tion\\npm', 'run', 'dev'] Debug: Starting frontend Debug: Debug: > dev Debug: > next dev Debug: Debug: ▲ Next.js 14.0.1 Debug: - Local: http://localhost:3000 App running at: http://localhost:3000 Debug: Debug: ✓ Ready in 8.8s Debug: ○ Compiling / ... Debug: ✓ Compiled / in 40.5s (1598 modules) Debug: [?25h Compiling: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 15/15 0:00:00 ```

REF-1842

ElijahAhianyo commented 7 months ago

When you say hanging, do you mean the contents of the page doesnt show at all?

gunungpw commented 7 months ago

Yes the browser cannot open local host, it just try to open and hang/always loading, and sometimes it cannot connect

iddrisumohamme1 commented 7 months ago

That is really true . I experience the same problem.

picklelo commented 7 months ago

Do any previous versions of reflex work? Trying to understand if this was introduced in a new release.

gunungpw commented 7 months ago

Do any previous versions of reflex work? Trying to understand if this was introduced in a new release.

after investigation, the last version that works on my end is 0.3.3, after turning off the firewall and changing default port to 4000

when use the same trick on version 0.3.11, reflex run can be used and can open in the browser but each compiling process has delay

gunungpw commented 7 months ago

my guess this problem arises when windows 11 update change behaviour, when the first time you used reflex run windows UAC dialog appears on the screen asking for permission

gunungpw commented 7 months ago

for additional note, when i try testing with FastAPI, and NiceGUI another framework that similar to reflex. I don't get problem when serving to localhost. I hope reflex can fix the issue. I love the work you put in to this framework, I hope reflex can go big in python ecosystem.

gunungpw commented 7 months ago

extra note, opening localhost:8000/docs its working fine

ElijahAhianyo commented 7 months ago

windows UAC

Hey @gunungpw out of curiosity, do you happen to remember what permission specifically the UAC dialog was asking to grant access? Is it the python executable?

Also after granting access, does the issue still persist? or are you able to access the page content in the browser now?

tien-tran0906 commented 7 months ago

Hey, I'm experiencing the same issue. Here's the UAC dialog.

Screenshot 2024-02-17 183050

I tried checking all the boxes above, still doesn't work.

On my Windows laptop, I tried Google Chrome and MS Edge, still no difference. But when I get onto my Mac, the problem doesn't exist anymore.

Reflex version before 0.4.0 doesn't seems to have this problem in my experience.

ElijahAhianyo commented 7 months ago

Hey, I'm experiencing the same issue. Here's the UAC dialog.

Screenshot 2024-02-17 183050

I tried checking all the boxes above, still doesn't work.

On my Windows laptop, I tried Google Chrome and MS Edge, still no difference. But when I get onto my Mac, the problem doesn't exist anymore.

Reflex version before 0.4.0 doesn't seem to have this problem in my experience.

start times on Windows seem to take long and give the impression of the page not being accessible. Just to have a better sense that this is not the case, can you run reflex in debug mode reflex run --loglevel debug and show the complete output? Also, if you wait till the app runs and see Debug: ready in xs(where x is an actual number and s is the seconds SI unit) in your console, are you able to access the content of the page?

As a side note, we recently released a new version 0.4.1 to fix a reload issue on Windows. can you also give that a shot to see if the issue persists?

tien-tran0906 commented 6 months ago

Thank you for addressing the issue. I've installed reflex 0.4.1, but seems like the issue still persists. Here's the screenshot:

reflex1

When running reflex run --loglevel debug for the first time, seems like it took 2.7s. Then I tried to make some minor changes, saved the code, but seems like the issue still persists. The code compiled to 100%, and it just stopped there, for about 5 minutes, I get this screen ( I also get the same screen when do Ctrl + R to hard refresh at anytime): reflex2

masenf commented 6 months ago

@tien-tran0906 Can you try with python3.11 instead of 3.12. Uvicorn still has some issues with 3.12 support on windows. Not clear when they will be able to fix them.

gunungpw commented 6 months ago

I got same problem with reflex 0.4.1 and Python 3.12, will try Python 3.11

tien-tran0906 commented 6 months ago

IT WORKS! I tried with Python 3.11.7. Got the complied time and page auto reload is just fine: reflex4

gunungpw commented 6 months ago

The problem is gone when using 3.11. reloading works fine when editing file. Thank you all, have a nice day.

masenf commented 6 months ago

I believe uvicorn-0.22.0 broke windows reload support on python < 3.12. So it might be theoretically possible to use the newer uvicorn only on py3.12 if we can test sufficiently, and keep the older uvicorn for previous python versions.

The team will keep an eye on this issue. Thanks for testing and reporting back.