hlipnick's avatar

Vite HMR Broken in Safari

I have a Filament app in Laravel 10 using vite with hot module replacement (standard-ish setup. Just default vite config + custom Filament theme). The hot module refreshing work perfectly in Chrome, but in Safari, it renders a blank page. What's stranger, is if I refresh in Safari or save the file in my code editor again, the page refreshes correctly. So, bizarrely, I could just save every file twice and it would work, but I'd like to avoid that. On the failing cycles, Safari reports a 500 error with a Livewire endpoint, but I haven't been able to track down or fix the source.

Safari error: [Error] Failed to load resource: the server responded with a status of 500 () (livewire.js, line 0) https://appname.test/livewire/livewire.js?id=5eee0fac.

I am running on a Mac and hosting the local dev with Valet (secured) and visiting the site at the https location.

Appreciate any help or pointers. Thanks!

0 likes
2 replies
LaryAI's avatar
Level 58

It sounds like you're encountering an issue with Vite's Hot Module Replacement (HMR) when using Safari. The 500 error with the Livewire endpoint suggests that there might be a server-side issue or a misconfiguration. Here are a few steps you can take to troubleshoot and potentially resolve the issue:

  1. Check the Network Tab in Safari's Developer Tools: Open the Network tab in Safari's Developer Tools to see if there are any additional details about the 500 error. This might give you more insight into what's going wrong.

  2. Check Laravel Logs: Look at the Laravel logs in storage/logs/laravel.log for any error messages that occur when the 500 error is triggered. This can help you pinpoint the source of the problem.

  3. Ensure Livewire Assets are Up to Date: Make sure that you are serving the latest version of Livewire's assets. You can force-publish Livewire's assets with the following command:

    php artisan livewire:publish --assets
    
  4. Check Vite Configuration: Ensure that your vite.config.js file is correctly set up to handle HMR. You might need to specify the server's host and port explicitly if it's not the default. For example:

    export default {
      server: {
        hmr: {
          host: 'appname.test',
          port: 3000, // or the port you're using for HMR
        }
      }
    }
    
  5. Check for HTTPS Issues: Since you're using Valet in a secured (HTTPS) environment, make sure that there are no issues with SSL certificates that might be causing the problem. You can try temporarily using HTTP to see if the issue persists.

  6. Clear Caches: Sometimes, old cached assets can cause issues. Clear your Laravel cache, browser cache, and any other caches that might be relevant.

    php artisan optimize:clear
    
  7. Check Livewire Configuration: Ensure that Livewire is properly configured to work with Vite. You may need to adjust the asset_url in the Livewire configuration to match your local development URL.

  8. Update Dependencies: Make sure that all your dependencies, including Laravel, Livewire, and Vite, are up to date. Sometimes, bugs that cause these issues are fixed in newer versions.

  9. Check Browser Console for JavaScript Errors: Sometimes, JavaScript errors can prevent HMR from working correctly. Check the browser console for any errors and address them if found.

  10. Try a Different Port: Occasionally, the default port might have conflicts. Try running Vite on a different port to see if that resolves the issue.

If none of these steps resolve the issue, consider creating a minimal reproduction of the problem and submitting an issue on the Vite or Livewire GitHub repository, as it might be a bug that the maintainers need to address.

hlipnick's avatar

Upgrading Livewire from 3.4.1 -> 3.4.4 seemed to fix the issue. Haven't had time to see what changed that fixed it, but happy to have it working again.

Please or to participate in this conversation.