question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

App keeps refreshing with log: `Server connection lost polling for restart`

See original GitHub issue

Describe the bug

In certain situation the app keeps refreshing indefinitely giving this log in console: server connection lost polling for restart.

I’m using vite 2.4.2 with https, react and typescript.

Reproduction

I noticed this happen in this 2 situations:

  1. Using Brave with a CORS extension enabled on the page (in my case is CORS Unblock). Weirdly using Chrome with the same Chromium version and same extension doesn’t cause the problem
  2. Running vite with the --host flag and accessing it with my phone (Safari on iOS 14) via the shared url: https://192.168.1.xxx:3000. Removing the https option “solves” the problem on iOS.

System Info

System:
    OS: macOS 11.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 808.27 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
Binaries:
    Node: 14.17.3 - /usr/local/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 6.14.13 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
Browsers:
    Brave Browser: 91.1.26.74
    Chrome: 91.0.4472.114
    Firefox: 88.0.1
    Safari: 14.1.1

Used Package Manager

yarn

Logs

No response

Validations

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:41 (3 by maintainers)

github_iconTop GitHub Comments

12reactions
aflansburgcommented, Dec 21, 2021

I experienced this same issue when building with docker. In the container my app runs on port 3000, however, as I have another app running on that port on my local I am using 3001 as my host port. From my docker-compose.yml for my Svelte+Vite app:

  web-frontend:
    build:
      context: ./svelte-vite-frontend-dock
      dockerfile: Dockerfile
    volumes:
      - ./svelte-vite-frontend-dock:/usr/src/app
      - /usr/src/app/node_modules
    ports:
      - 3001:3000
      - 24678:24678

Clues above in posts regarding people using reverse proxies made me realize that I needed to add this to my vite.config.js file:

server: {
    hmr: {
      clientPort: 3001,
    },
  },

This immediately fixed my issue.

9reactions
FossPrimecommented, Sep 21, 2021

In CodeSandbox traffic is routed to port 3000 from an SSL proxy on port 443. Vite will by default look for port 3000, instead of port 443. The only configuration needed to make it work was changing the HMR port.

server: {
    hmr: {
      port: 443
    }
  }

Working codesandbox: https://codesandbox.io/s/vite-hmr-fix-4259-h6c2l?file=/vite.config.ts:180-227

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Vite - React - App keeps refreshing with log: Server ...
Issue : Suddenly app keeps refreshing indefinitely giving this log in console: server connection lost polling for restart.
Read more >
Websocket issue in shopify Express App on server
Everything works fine in my local environment but when I run the app on the server I get an infinite loop with the...
Read more >
Problem with Laravel 9 and Vite in combination with vagrant
firefox can't establish a connection to the server ws://domain.test:3000/ aufbauen. client.ts:22:15 [vite] server connection lost. polling for restart.
Read more >
Understanding and Handling Connection Lifetime Events in ...
When a server goes offline -- it reboots, fails, the app domain recycles, etc. -- the result might be similar to a lost...
Read more >
Kept having popup of "Connection Lost" and ... - Odoo
Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps: CRM; e-Commerce; Accounting; Inventory; PoS; Project ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found