withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
45.64k stars 2.39k forks source link

Dev server breaks after making code changes on fresh template install #7807

Closed nicholasq closed 1 year ago

nicholasq commented 1 year ago

What version of astro are you using?

2.9.3

Are you using an SSR adapter? If so, which one?

no

What package manager are you using?

pnpm

What operating system are you using?

Mac M1

What browser are you using?

Firefox, Edge

Describe the Bug

UPDATE: Please read my first comment. I believe this is an issue with Intellij IDEA.

The server appears to lock up and stop serving resources after making 5-10 changes (triggering HMR). It seems the websocket dies. All you need to do is start up a fresh install from a template, start the server, comment out some css about 5-10 times, then click another page within the web page and the page will refuse to load. A server restart is needed in order to 'fix' the pages not loading.

Steps to reproduce:

First install either blog or portfolio template: pnpm create astro@latest -- --template blog or pnpm create astro@latest -- --template portfolio

Then start server: pnpm run dev

Open browser and go to localhost:3000

In your editor just start making minor changes to pages, then click save so hot module reloading reloads the page in browser. Do this a bunch of times (making changes to trigger HMR). Just comment out some css or something. Click save. Repeat 5-10 times. Then go to the page and try to navigate to another page. The page won't load. You will see this in the browser console:

The connection to ws://localhost:3000/ was interrupted while the page was loading. 
[vite] server connection lost. polling for restart...

I have tested this in Firefox Developer Edition (the latest version as of today) and Edge (latest version as of today). It happens in both browsers.

What's the expected result?

I expect to be able to make changes to code and the dev server to hot reload and not die on me. I have to restart the dev server constantly because of this issue.

Link to Minimal Reproducible Example

https://stackblitz.com/this-is-unnecessary

Participation

nicholasq commented 1 year ago

TL;DR: I believe this issue is caused by Intellij IDEA. I will report it to Jetbrains.

Ok I want to add an update. I have narrowed it down. I did lots of testing on my mac, and remotely using vscode remote tunnels with dev containers.

When I first reported this error, I was using Intellij IDEA Ultimate 2023.2. I decide to try using vscode, and creating/running the server with yarn/pnpm on a linux container on a linux host. I didn't have any issues.

I have finally narrowed it down. it's the 'run anything' function in Intellij IDEA that seems to be causing this. 'Run anything' is a feature of intellij where you can double tap control and run a script command without opening a terminal. If i run the server from this feature pnpm run dev, I will get the server failure issue. I would believe that this isn't an problem that astro devs can fix. I will report this problem to Jetbrains.

natemoo-re commented 1 year ago

Thanks for the update @nicholasq! Going to close this as it's an upstream issue, but let us know if there's anything we can help with in the future.