Skip to content

Excluding Livewire views from the current full-page-reload behavior #11

Closed

Description

@Random72IsTaken

Greetings,

The following are the only versions I managed to get Livewire hot-reloads working with:

  • vite@2.9.14
  • laravel-vite-plugin@0.2.4
  • @defstudio/vite-livewire-plugin@0.1.15

And this is how I configured the vite.config.js file:

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import livewire from '@defstudio/vite-livewire-plugin';

export default defineConfig({
    plugins: [
        laravel([
            'resources/css/app.css',
            'resources/js/app.js',
        ]),
        {
            name: 'blade',
            handleHotUpdate({ file, server }) {
                if (
                    file.endsWith('.blade.php') &&
                    !file.includes('/livewire/')
                ) {
                    server.ws.send({
                        type: 'full-reload',
                        path: '*',
                    });
                }
            },
        },
        livewire({
            refresh: ['resources/css/app.css', 'resources/js/app.js'],
        }),
    ],
});

I had to downgrade them and used Freek's solution because I have no idea about accounting for this in the new versions:

files in /livewire/ should be excluded from blade hot reload.

Can you please teach me how? 🙃

Activity

  1. fabio-ivona commented on Jul 31, 2022

    @fabio-ivona
    Member

    Hi, could you please share the configuration you are trying to set up?

  2. Random72IsTaken commented on Jul 31, 2022

    @Random72IsTaken
    Author

    It's nothing fancy really! I just want to know how the current default Laravel-Livewire setup would work with this plugin! Because their current version does reload ALL blade files anyway, even if you set their plugin's refresh to false, as far as I tested...

    But you've mentioned that we need to disable that page-reloading feature in order for the livewire plugin to do the reloading instead. And I don't know how one would do that with the new config file -which would look something like this, probably:

    import { defineConfig } from 'vite';
    import laravel from 'laravel-vite-plugin';
    import livewire from '@defstudio/vite-livewire-plugin';
    
    export default defineConfig({
        plugins: [
            laravel({
                input: [
                    'resources/css/app.css',
                    'resources/js/app.js',
                ],
                refresh: true,
            }),
            livewire({
                refresh: ['resources/css/app.css'],
            }),
        ],
    });

    So you see this setup (with all versions up-to-date), I don't think it works, dude! From what I have tested, the page still fully reloads when only Livewire changes are there. And we get that exception thrown in the browser by this package that the page was reloaded by some other conflicting page-reloading thingie! 😵‍💫

  3. fabio-ivona commented on Jul 31, 2022

    @fabio-ivona
    Member

    Laravel plugin blade reload conflicts with this plugin, because it calls a full reload during livewire hot reload

    The reason is that often you have livewire components that include blade components

    To solve this, the last version of livewire plugin implements an opt-in full reload that adds a small checkbox on the bottom right corner of the page that allows you to switch between livewire hot reload and full page reload (handled by livewire plugin) when a blade file changes

    So you should disable laravel refresh and enable livewire opt-in refresh by adding an VITE_LIVEWIRE_OPT_IN=true entry in your .env file

  4. Random72IsTaken commented on Jul 31, 2022

    @Random72IsTaken
    Author

    Oh, I see. So that's how it's done. Thank you! 🙂

  5. locked and limited conversation to collaborators on Jul 31, 2022
  6. converted this issue into a discussion #12 on Jul 31, 2022
  7. added a commit that references this issue on Aug 3, 2022
    6a5683c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions