Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser not reloading #68

Closed
datencoach opened this issue Feb 18, 2022 · 25 comments
Closed

Browser not reloading #68

datencoach opened this issue Feb 18, 2022 · 25 comments

Comments

@datencoach
Copy link

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
Copy link
Owner

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
Copy link
Author

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

@shawnngtq

This comment was marked as off-topic.

@adamchainz

This comment was marked as off-topic.

@shawnngtq

This comment was marked as off-topic.

@datencoach
Copy link
Author

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
Copy link
Author

datencoach commented Feb 21, 2022

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
Copy link
Owner

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

@datencoach
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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?

def events(request: HttpRequest) -> HttpResponseBase:
if not settings.DEBUG:
raise Http404()
if django.VERSION >= (3, 1) and not request.accepts("text/event-stream"):
return HttpResponse(status=HTTPStatus.NOT_ACCEPTABLE)
def event_stream() -> Generator[bytes, None, None]:
while True:
yield message("ping", versionId=version_id)
should_reload = should_reload_event.wait(timeout=PING_DELAY)
if should_reload:
should_reload_event.clear()
yield message("reload")
return StreamingHttpResponse(
event_stream(),
content_type="text/event-stream",
)

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

@datencoach
Copy link
Author

datencoach commented Mar 3, 2022

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 True after 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
Copy link
Owner

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

@adamchainz
Copy link
Owner

adamchainz commented Mar 3, 2022

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

datencoach commented Mar 26, 2022

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
Copy link

rakyi commented Jul 21, 2022

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

@adamchainz
Copy link
Owner

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

Repository owner locked as resolved and limited conversation to collaborators Jul 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants