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

https://nicegui.io/ Automatically refresh without reason (with Safari) #1211

Closed
liang-jacky opened this issue Jul 21, 2023 · 12 comments · Fixed by #1262 or #1300
Closed

https://nicegui.io/ Automatically refresh without reason (with Safari) #1211

liang-jacky opened this issue Jul 21, 2023 · 12 comments · Fixed by #1262 or #1300
Assignees
Labels
bug Something isn't working
Milestone

Comments

@liang-jacky
Copy link

Description

When I visit the website to view documents for learning, the page automatically refreshes without any reason, resulting in a poor experience. I hope the author can investigate this phenomenon. Thank you

@rodja
Copy link
Member

rodja commented Jul 21, 2023

Thanks for reporting this. We have seen this before and are investigating possible solutions. We will update any progress here!

@rodja rodja self-assigned this Jul 21, 2023
@rodja rodja added the bug Something isn't working label Jul 24, 2023
@rodja
Copy link
Member

rodja commented Jul 26, 2023

Quite tricky! After long investigations and multiple ping-pong with the fly.io support I can summarize:

  1. NiceGUI serves the initial website which then needs to connect back to the server with socket.io to keep browser and backend in sync.
  2. https://nicegui.io runs multiple instances around the globe for minimum latency and spawns new instances in each region according to traffic.
  3. As long as there is only one server per region, the socket.io websocket connection is routed back to the right instance which has served the website.
  4. In the last few weeks we have experienced more and more traffic; most of the time spiking in one or two regions.
  5. This resulted in additional instances where demand is high -- and reduced the chance that socket.io connects back to the correct instance, resulting in page reloads until the user get's lucky.

To fix this we need to route the socket.io connection back to the original instance which served the page. fly.io provides a fly-force-instance-id header. Unfortunately web browsers do not allow to set custom headers for websocket connections. Therefore the fix in #1262 changes the socket.io transport from websocket to long polling. Not ideal but I have no other solution right now.

I spend quite some time to evaluate Google Cloud Run as an alternative to fly.io because they have cookie-based session affinity. But I have not been able to reduce the initial resposnse time below 1.5 seconds yet.

@falkoschindler
Copy link
Contributor

@rodja Could #1212 be related?

@rodja
Copy link
Member

rodja commented Jul 26, 2023

@rodja Could #1212 be related?

Yes. I hope so. I'll try once we have released the fix #1262 into production.

@falkoschindler falkoschindler added this to the 1.3.6 milestone Jul 26, 2023
@pythonormen
Copy link

Hope you will find a solution for this as it must be such an unnecessary negative first impression for new users.

Also will it improve the user experience on mobile?
Nicegui site is so slugish on mobile.

@rodja
Copy link
Member

rodja commented Jul 29, 2023

@pythonormen is it still happening for you? We have released a fix a few days ago and could not reproduce the error anymore.

@Xtreemrus
Copy link

Hello, for page https://nicegui.io/documentation/tree#expand_programmatically still auto refresh again and again.
Safari 16.1 (18614.2.9.1.12)

@rodja
Copy link
Member

rodja commented Jul 29, 2023

You are right. On Chrome all looks good. But on Safari it is inacceptable:
Jul-29-2023 15-38-14

@rodja rodja reopened this Jul 29, 2023
@rodja rodja changed the title https://nicegui.io/ Automatically refresh without reason https://nicegui.io/ Automatically refresh without reason (with Safari) Jul 29, 2023
@rodja
Copy link
Member

rodja commented Jul 31, 2023

I think I found a solution in the minimal example https://github.com/zauberzeug/fly_fastapi_socketio. It seems that it is indeed possible to inject headers into the response of an websocket upgrade request. Feels hacky but works.
I'll now try to implement it for our website.

@rodja
Copy link
Member

rodja commented Jul 31, 2023

@Xtreemrus we just released a hotfix with PR #1300 to the public website. It looks good on my side. Can you please test and verify that the bug is really fixed?

@Xtreemrus
Copy link

@Xtreemrus we just released a hotfix with PR #1300 to the public website. It looks good on my side. Can you please test and verify that the bug is really fixed?

Fixed :)

@rodja rodja closed this as completed Jul 31, 2023
@rodja
Copy link
Member

rodja commented Jul 31, 2023

Thanks for going all the way @Xtreemrus. I'm happy you persisted in this. The new solution is much cleaner and better. It was quite an effort. But worthy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants