MysticKnight's avatar

Hot Reloading Fails

This seems like it should be such a simple problem to solve, but I have searched for days without finding and answer.

Environment:

  • Mac OS
  • Chrome
  • Herd for Laravel Installation with Breeze

I had a Laravel project and I decided to completely delete it and start over.

I started from scratch, but I used the same name for the project and now hot reloading doesn’t work.

I can see that Vite is reloading the files in the terminal when I make a change, but the file in the browser doesn’t change unless I reload it.

I’ve tried clearing browser cache and clearing Laravel cache, but I can’t get it to work.

If I create a new project with a new name, hot reloading works just fine.

I figure people do this all the time, so I’m surprised it has problems.

Any advice or tips would certainly be appreciated.

Best regards, Bill

0 likes
10 replies
RemiM's avatar
  1. Terminate processes running in the background related to Vite and Node.js:
pkill -f vite
pkill -f node
  1. Clear Laravel and Vite caches:
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
rm -rf node_modules package-lock.json
rm -rf bootstrap/cache/*
npm install

Then start your Vite dev server:

npm run dev
  1. Force refresh in the browser:
Cmd/Ctrl + Shift + R
MysticKnight's avatar

First, thank you for your reply.

I have tried those steps already without success.

I’ve done additional tests and it seems to be tied to the local SSH certificate that I created with this command…

herd secure

When I deleted my original project, it does not delete the secure certificate that it created for that project.

I figured out where it stores those files and manually deleted them and hot reloading worked again using http:// instead of https://.

But as soon as I tried to secure it again with herd secure, it broke hot reloading.

Batman55's avatar

@mysticknight Is this maybe a bigger issue?

I currently can not use Chrome with Vite as it continually freezes and crashes. I have not had any issues with FIrefox, Safari, or even other chromium based browsers. It started at the last Chrome update.

I am using Mac 13.7.3 Ventura on an Intel MBP. Chrome Version 133.0.6943.100 (Official Build) (x86_64).

MysticKnight's avatar

@Batman55 I don't think that's the problem for me.

My other Laravel Herd projects work just fine with Chrome.

It definitely has something to do with using the same project name and the SSH certificates when I run this:

herd secure

The https// path isn't being updated somewhere.

After doing a bit more research today, I found out that if I add the following code to my vite.config.js file, it fixes the hot reloading problem...

server: {
    host: 'projectname.test', // Ensures it's accessible from the correct domain
    port: 5173, // Default Vite port, but you can change it if needed
    hmr: {
        host: 'projectname.test', // Ensures HMR connects properly
    },
},

I'm glad that it's working now, but I still want to find out why it's necessary to modify my vite.config.js file like that.

1 like
billythekid's avatar

Thanks for this, adding that config sorted this out for me. I normally don't bother with a secure site locally but it was becoming ever more annoying that 1Password wouldn't autofill the login form without https:

RemiM's avatar

First, do you really need a secure site in dev environement?

If it was working without the serverentry prior to the problem, then you technically don't need it.

To check what's going on, run the command:

herd secured

You should see something like this:

+----------------------------+----------------------------+
| Site                       | Valid Until                |
+----------------------------+----------------------------+
| expose.dev.test            | 2024-08-10 12:07:38 GMT    |
| herd-templates.test        | 2024-09-05 25:12:77 GMT    |
| reverb-110.test            | 2024-09-11 13:44:56 GMT    |
| tinkerwell.app.test        | 2024-10-16 19:53:32 GMT    |
+----------------------------+----------------------------+

What you can try to do is unsecure the site that gives you problems:

herd unsecure example-site 

Double check herd securedto be sure the site is no longer there, then herd secure example-site and finally:

php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
1 like
MysticKnight's avatar

You know Remim, I was asking myself the same question. I was following an instructional video and that’s what they did, so I just followed along.

I’m deep enough into this now that I want to know more about it. I’m going to try what you suggested and see what happens.

MysticKnight's avatar

For what it’s worth, here’s what ChatGPT thinks about using ‘herd secure’ for my local development environment…

——

Using Herd Secure in your local development environment depends on your needs. Here are some considerations:

Reasons to Use Herd Secure:

  1. Testing HTTPS Locally – If your project interacts with services that require HTTPS (e.g., OAuth, Stripe, API integrations), Herd Secure makes it easy to test without self-signed certificate hassles.

  2. Matching Production Environment – If your production site runs on HTTPS, testing locally under the same conditions can help catch mixed-content issues and other SSL-related problems.

  3. Service Worker & PWA Development – Some browser features (like service workers or PWA installations) require HTTPS, even in development.

  4. Secure Cookie Handling – If you’re working with Secure or SameSite cookie settings, you may need HTTPS to test their behavior properly.

Reasons Not to Use It:

  1. Unnecessary Overhead – If your project doesn’t require HTTPS-related testing, enabling it won’t provide much benefit.

  2. Local-Only Development – If your app doesn’t interact with external services that enforce HTTPS, you likely don’t need it.

If any of your projects involve API authentication, payments, or PWA features, it’s worth enabling. Otherwise, it’s not essential.

——

In my case, I have no reason to use ‘herd secure’ so I’m just going to leave that out of my procedure when creating a new project, but I thought I would post that info in case someone else finds it helpful.

karuna's avatar

I found that the hot reloading didn't work on my livewire sites until I asked Herd to use the latest version of PHP.

Please or to participate in this conversation.