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

Wait for online before polling the dev server for availability in @vite/client.ts #6791

Closed
4 tasks done
vursen opened this issue Feb 7, 2022 · 4 comments
Closed
4 tasks done

Comments

@vursen
Copy link
Contributor

vursen commented Feb 7, 2022

Clear and concise description of the problem

It is technically possible to get Vite apps to work offline in dev mode. Just configure your service worker so that it caches every request to the Vite dev server except for __vite_ping requests. The latter is important to prevent @vite/client from falling into a recurring page reload: when the network connection is lost, @vite/client pings the dev server every 1 sec and reloads the page as soon as the server responds with the HTTP 200 status.

Now that you managed to run your app offline, the only problem is, you see a huge number of failed ping requests on the DevTools Network tab and in the browser console. They are quite distracting when you are testing something and are essentially unnecessary work.

Suggested solution

It would be better if @vite/client waited for navigator.onLine to become true and only then started polling the dev server for availability. This way it will save unnecessary ping requests and avoid unnecessary noise in DevTools.

Alternative

No response

Additional context

No response

Validations

@vursen vursen changed the title Make @vite/client wait online before polling the dev server for availability Wait for online before polling the dev server for availability in @vite/client.ts Feb 7, 2022
@bluwy
Copy link
Member

bluwy commented Feb 7, 2022

Not sure about checking navigator.onLine before pinging, as technically the ping is still useful even without internet connection as the dev server is local only?

@patak-dev
Copy link
Member

patak-dev commented May 17, 2022

@vursen would you check if this is still a issue after #6819?

@vursen
Copy link
Contributor Author

vursen commented May 20, 2022

@patak-dev This is still an issue. The only thing that changed is the actual ping URL: it is now something like http://localhost:45453/VAADIN/ instead of http://localhost:45345/VAADIN/__vite_ping.

Not sure about checking navigator.onLine before pinging, as technically the ping is still useful even without internet connection as the dev server is local only?

Good point. Perhaps what I'm seeking is a configuration option with that I could control how many attempts to reconnect should the Vite client make, say per 1 sec. In order to completely disable the auto-reconnect, the option could be set to Infinity. Or more generally, we just need an API that would allow us to turn off the auto-reconnect for the time being.

@sapphi-red
Copy link
Member

Perhaps what I'm seeking is a configuration option with that I could control how many attempts to reconnect should the Vite client make, say per 1 sec.

I think this is a duplicate of #5228.

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Jul 9, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jul 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants