FHoulbreque's avatar

Strange hot reload issue

Hello there,

I have a strange issue while using vite hot reload while developing a new livewire app. It does update correctly the component on save but sometimes, when I click in one input and start to type, it will reload again, even when there's no "live" model or any kind of live request. It reload and lose state.

Is there an option I should check in any configuration if I want to avoid this annoying behaviour?

Thank you for your help.

0 likes
4 replies
LaryAI's avatar
Level 58

The issue you're experiencing with Vite's hot reload in a Livewire application could be due to a few different factors. Here are some steps you can take to troubleshoot and potentially resolve the problem:

  1. Check Vite Configuration: Ensure that your Vite configuration is set up correctly. Sometimes, incorrect settings can cause unexpected reloads. Look for any settings related to hot module replacement (HMR) and ensure they are configured properly.

  2. Livewire Configuration: Make sure that your Livewire components are not inadvertently causing a reload. Check for any Livewire directives or properties that might be triggering a refresh when interacting with inputs.

  3. Inspect Console for Errors: Open your browser's developer tools and check the console for any errors or warnings that might give you a clue about what's causing the reload.

  4. Disable HMR Temporarily: As a test, try disabling HMR to see if the issue persists. You can do this by modifying your Vite configuration. If the problem goes away, it might be related to how HMR is interacting with your Livewire components.

  5. Check for External Scripts: Sometimes, external scripts or libraries can interfere with the normal operation of your app. Ensure that no third-party scripts are causing the reload.

  6. Update Dependencies: Ensure that all your dependencies, including Vite, Livewire, and any other related packages, are up to date. Sometimes, bugs are fixed in newer versions.

  7. Review Input Elements: Double-check the input elements in your Livewire components. Ensure that they are not bound to any properties or methods that might cause a reload when they change.

Here's a basic example of how you might configure Vite for a Laravel project:

// vite.config.js
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true, // Ensure this is set correctly
        }),
    ],
});

If none of these steps resolve the issue, consider creating a minimal reproducible example and posting it on the forum or GitHub for further assistance. This will help others understand the problem better and provide more targeted help.

FHoulbreque's avatar

I tried today to go through the course from Jeremy McPeak about Livewire 3 fundamentals and following exactly his setup, I experience the same behaviour from vite... It can be something everyone experiences, but I never seen this on any video made by anyone so it is probably something else.

To be perfectly clear on what's happening, I make a change on any file, and the page reload as normal, but as soon as I focus a form field and try to tipe something, it start a full page reload at once that wipe the current state of the form. It doesn't happen again afterward until I make another change to the PHP side of the component I think, this doesn't occur when only changing blade side of the component, mostly (it can still happens).

Please or to participate in this conversation.