adamchainz / django-browser-reload

Automatically reload your browser in development.
MIT License
513 stars 26 forks source link

Browser not reloading #68

Closed datencoach closed 2 years ago

datencoach commented 2 years ago

Python Version

3.9.10

Django Version

4.0.2

Package Version

1.3.0

Description

Did an update on django-tailwind from 2.x to 3.1.1 and also changed from browser-sync to django-browser-reload. Followed the update instructions and compared all steps to a previously updated project without any problems.

But this time the browser just does not reload on changes. The script-Tag is in the source code of the page. Tailwind start does recognize the updated html or css. But the browser does not reload. No GET request to update the site is fired.

Do you have any idea where I can look for the problem?

adamchainz commented 2 years ago

what browser? safari is known not to work

you can debug the worker and check its log messages: https://lihautan.com/Debugging%20web%20workers/

datencoach commented 2 years ago

Chrome and Firefox, sorry for leaving out. There is no workers context in dev tools.

adamchainz commented 2 years ago

any logging in your console on main pages?

you can see what will be logged in the scripts

https://github.com/adamchainz/django-browser-reload/blob/main/src/django_browser_reload/static/django-browser-reload/reload-listener.js https://github.com/adamchainz/django-browser-reload/blob/main/src/django_browser_reload/static/django-browser-reload/reload-worker.js

shawnngtq commented 2 years ago

Maybe relevant, ./manage runserver works but ./manage runserver_plus (django-extensions) doesn't

adamchainz commented 2 years ago

@shawnngtq that is probably a different issue. Can you open one? Also I don't particularly care to support django-extensions but if you can find a simple patch or docs fix I would merge that. Possibly runserver_plus doesn't support threads or long running views by default.

shawnngtq commented 2 years ago

It's ok, I just stick to the ./manage runserver, this is a feature and not a bug. And not a very important one. 😁

Just thought that datencoach might be doing it via ./manage runserver_plus.

datencoach commented 2 years ago

No, I am using runserver. I did not have a chance to check during weekend and will not be able to check today. But there are no logging messages in the console. I will compare it with the working project and provide screenshots. Thanks for your help.

datencoach commented 2 years ago

No output to console in browser. Of course, no new request to the server. But CSS was rebuilt after change in HTML.

2022-02-21 21_00_36 2022-02-21 21_01_52-home html - coworking - Visual Studio Code

I checked again the project I updated earlier, no problems. Reloading on any change.

adamchainz commented 2 years ago

Please also check the worker logs as per the link in my first comment

datencoach commented 2 years ago

No workers in Javascript context and no workers in "shared workers" 2022-02-22 07_11_27-Inspect with Chrome Developer Tools

As mentioned before the script tag is set in the source code 2022-02-22 07_12_01-view-source_127 0 0 1_8000

adamchainz commented 2 years ago

You may have something on your page that prevents the script even starting.

If you see the listener script logs if it's not possible to start the worker:

https://github.com/adamchainz/django-browser-reload/blob/main/src/django_browser_reload/static/django-browser-reload/reload-listener.js

So either you should see that message, or the worker should start.

Are you allowing debug-level messages on your devtools console?

Are there other messages you're ignoring?

Can you try adding extra log messages to your local version of the script (edit it within your virtualenv) to see where it gets to?

datencoach commented 2 years ago

Thank you for your help.

I put some console log statements into the script. The script runs. A worker is created. EventListener does not receive any events to trigger the reload. 2022-02-26 09_10_45-Coworking Space Stade

adamchainz commented 2 years ago

Okay - that's interesting. Would you be able to add some print() statements into the view to determine if a connection is made, and if ping messages are sent?

https://github.com/adamchainz/django-browser-reload/blob/0d40e4edf65343513e04663a488ba2ac3a706e13/src/django_browser_reload/views.py#L145-L164

(I opened #69 to add some log messages to the source permanently, for future debugging.)

datencoach commented 2 years ago

Sure.

View events is running on startup and page refresh. Function event_stream is called and while loop is running. should_reload is set to Trueafter change and save on a html template.

But still no refresh within the browser. As written before. Same setup on a different project work just fine. I am not able to spot any difference.

adamchainz commented 2 years ago

Huh. And this is with normal runserver, no packages replacing it, and you're not using the --nothreading option?

adamchainz commented 2 years ago

I would normally ask to reproduce the bug in a small project but I suspect it would be hard to do so without narrowing down the problematic component.

datencoach commented 2 years ago

yes, straight runserver. nothing fancy. The only difference is Wagtail. The running project is straight Django.

No worries. I can work without reloading. And if no other user has the same problem, we should not spend too much time on it.

adamchainz commented 2 years ago

I'm happy to keep debugging, if you are.

As I understand, you added print()s within the while loop, so you could see messages were being yielded by the view? That would imply that a worker is running and connected, and somehow receiving them...

datencoach commented 2 years ago

Sure, I am.

Yes, correct. 2022-03-05 16_24_06-views py - coworking - Visual Studio Code

2022-03-05 16_24_22-views py - coworking - Visual Studio Code

adamchainz commented 2 years ago

Okay, it seems impossible then that you'd not see a worker running. Clearly something is connected and receiving the events. Can you try checking the relevant debugging panels in both browsers, as per https://lihautan.com/Debugging%20web%20workers/ ?

datencoach commented 2 years ago

I still do not see any worker in javascript context 2022-03-09 07_56_50-Coworking Space Stade

But I can see it on chrome://inspect/#workers 2022-03-09 08_32_35-DevTools

Still no reloading.

Checked on the "running" project. Same picture. 2022-03-09 08_22_30-DevTools

adamchainz commented 2 years ago

Okay, I finally give up.

For your case, we've seen the server side component is running and sending messages, and the client side component is connecting and logging its "connected message". So it seems almost impossible that it wouldn't work.

Perhaps you have some kind of development tool (an option in devtools, or an extension) that is blocking the exact JS API's used to signal the reload.

I'd recommend you try a clean chrome profile with no extensions, or even another browser (Firefox!).

Happy to fix something if you get more data on this, but it seems the package is working fine for at least hundreds of people at this point, so it's probably not an issue here...

datencoach commented 2 years ago

Thanks for your help. Yes, I agree. The browser is not the problem as it is on any browser the same problem and it works with another project with identical setup. ... I could try screen recording to proof it is not working, but anyway. Fine with me. I will change my development setup shortly and it will be interesting to see if it works on the new laptop. Thanks, Adam. I appreciate your efforts to help me.

rakyi commented 2 years ago

I have what appears to be the same issue with both latest Firefox and Brave on macOS 12.5.

adamchainz commented 2 years ago

@rakyi Open a new issue if you have any new information. Please try capturing the debug logs at least.