Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Livewire 3 - Laravel 11 - Tailwind CSS double refresh issue with HMR #309

Open
FHoulbreque opened this issue Nov 26, 2024 · 4 comments
Open

Comments

@FHoulbreque
Copy link

FHoulbreque commented Nov 26, 2024

Vite Plugin Version

1.0.6

Laravel Version

11.33.2

Node Version

18.20.4

NPM Version

10.9.0

Operating System

Windows

OS Version

11 (23H2)

Web browser and version

Google Chrome 131.0.6778.86 (Official build) (64 bits)

Running in Sail?

No

Description

While progressing through development of my code (here it's coming from a course on Laracast) I encountered a strange behaviour with HMR:

  • When saving any change in the blade file, the page reload as intended
  • When changing PHP on the server side, it doesn't reload, which is I think normal as well.
  • But when interacting with input with wire:model or not on it, the page reload and reset the state. It doesn't occur every time, it generally occurs when there has been a change either on the blade or the PHP part of a liverwire component.

Steps To Reproduce

  • Change a file in a Livewire component
  • Observe an unwanted reload of the page while typing in an input field

Reproduction

https://github.com/FHoulbreque/vite-livewire-hmr-bug

@binaryfire
Copy link

binaryfire commented Nov 28, 2024

@FHoulbreque Just curious - do you see storage/framework/views/...... lines in your Vite console output when this happens?

I've hit a similar problem with Filament where field changes sometimes trigger a refresh. And there's always a corresponding line in the console output for a file in view cache directory. No idea why - I don't have any storage paths listed in my vite.config.js refresh paths.

@FHoulbreque
Copy link
Author

@binaryfire I thought you could be right, it could be related to the cache. But since I restarted vite with the -d parameter, I haven't had this bug once yet... I'll try to catch it this time.

A part of me thinks it could be related to the background save of files from PHPStorm but it wouldn't be just after I input one character in any field, it would be random, which it isn't. Furthermore I do save manually before I check the changes. As soon as I have a better information about this, I'll post it.

@FHoulbreque
Copy link
Author

FHoulbreque commented Nov 28, 2024

@binaryfire You were definitely right, it's related to a cached view file:

vite:hmr [file change] resources/views/livewire/article-list.blade.php +3s
20:26:37 [vite] page reload resources/views/livewire/article-list.blade.php
vite:hmr [file change] storage/framework/views/5fbfb808db058f00c0e0945a804c9a94.php +18ms
20:26:37 [vite] page reload storage/framework/views/5fbfb808db058f00c0e0945a804c9a94.php

The load of the view cache only happens when interacting with the page though.

@binaryfire
Copy link

binaryfire commented Nov 28, 2024

@FHoulbreque Thanks for confirming. I just realised ./storage/framework/views/*.php is defined in tailwind.config.js - that's why Vite is monitoring that directory. Maybe Livewire writes to the view cache on the fly for some reason? Hopefully someone who's more familiar with Livewire's internals can comment.

This only seems to have started in the last few weeks. So it might be because of a recent change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants