nystudio107 / craft-vite

Allows the use of the Vite.js next generation frontend tooling with Craft CMS
MIT License
51 stars 15 forks source link

@vite/client spotty #33

Closed chasegiunta closed 2 years ago

chasegiunta commented 2 years ago

Describe the bug

I know this has been an issue in the past, but possibly showing up again... Vite dev server is running, and navigating to localhost:3000/src/main.ts shows the right file, but localhost:3000/@vite/client is dead, thus dev server is not being detected as running if checkDevServer => true. What makes this difficult to repro is it seems pretty spotty.

Ultimately, I don't think this is an issue with craft-vite, but with vite itself, though I wonder if there's an alternative method to dev server detection.

Versions

khalwat commented 2 years ago

Give me a way to reproduce this, and I can try looking into it -- but I agree, it is likely an upstream issue of some sort.

chasegiunta commented 2 years ago

Currently, I have no way to get a response from localhost:3000/@vite/client with my vite dev server running, so if you're able with the latest version of vite (2.9.9), then you're a step ahead of me and maybe we can chalk this up to something local. Just putting it on your radar. If I figure out a way to fix/toggle it, I'll post more details.

khalwat commented 2 years ago

Run this locally:

https://github.com/nystudio107/devmode

Clone it down, cd to the directory, then do:

make clean
make dev

...and see if HMR works for you as expected.

chasegiunta commented 2 years ago

Okay, so localhost:3000/@vite/client won't be available until your app's entry file (in my case,main.ts) is requested from the browser first. This breaks checkDevServer => true because trying to ping localhost:3000/@vite/client returns 404.

Recreated by:

  1. checkDevServer => true
  2. Start vite dev server.
  3. Hit your homepage, or visit localhost:3000/@vite/client in your browser directly (both should be broke)
  4. Change checkDevServer to false
  5. Visit localhost:3000/@vite/client, ensure it's still inaccessible.
  6. Visit your homepage, dev server assets should serve as normal.
  7. Visit localhost:3000/@vite/client and the file should properly load.
khalwat commented 2 years ago

Okay, I think I found a fix... give me one moment...

khalwat commented 2 years ago

Addressed in:

Craft 4: https://github.com/nystudio107/craft-plugin-vite/releases/tag/4.0.1 Craft 3: https://github.com/nystudio107/craft-plugin-vite/releases/tag/1.0.25

khalwat commented 2 years ago

Released as:

Craft 4: https://github.com/nystudio107/craft-vite/releases/tag/4.0.0 Craft 3: https://github.com/nystudio107/craft-vite/releases/tag/1.0.25