Fix Vite asset loading on Android emulator with Herd HTTPS#129
Open
simonhamp wants to merge 2 commits into
Open
Fix Vite asset loading on Android emulator with Herd HTTPS#129simonhamp wants to merge 2 commits into
simonhamp wants to merge 2 commits into
Conversation
Laravel Herd auto-enables HTTPS on the Vite dev server using a self-signed cert that the Android emulator can't validate, causing all CSS/JS assets to fail to load. The laravel-vite-plugin runs with enforce: 'post' and only honours its own Herd/Valet TLS auto-detection when userConfig.server doesn't already declare host/https/hmr, so simply returning a partial config from our config() hook wasn't enough — laravel-vite-plugin still won. Force plain HTTP + the local LAN IP for HMR by: - Setting https: false and hmr.host/hmr.protocol in our server config for both the iOS and Android branches. - Mutating userConfig.server inside the config() hook (we already run with enforce: 'pre') so laravel-vite-plugin's fallback checks see our values and skip the Herd substitution entirely. Closes #109
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #109.
When Laravel Herd is installed, it automatically promotes the Vite dev server to HTTPS using a self-signed certificate. The Android emulator can't validate that cert, so every CSS/JS request to the dev server is rejected and the app renders unstyled.
nativephpMobile()already returned a server config pinned to the LAN IP, butlaravel-vite-pluginruns withenforce: 'post'and its Herd/Valet TLS auto-detection only steps aside whenuserConfig.server.host/.https/.hmrare already set. Returning a partial config from our hook isn't enough — laravel-vite-plugin still overwrites our values with Herd's hostname + cert.Changes
resources/js/vite-plugin.js:https: falseandhmr: { host: localIP, protocol: 'ws' }to the server block on both the iOS and Android branches.config()hook to takeuserConfigandObject.assignour server config ontouserConfig.serverbefore returning. BecausenativephpMobileisenforce: 'pre', this lands before laravel-vite-plugin's config hook readsuserConfig.server, so its fallback checks see our values and skip the Herd substitution.Result:
public/android-hot(andpublic/ios-hot) are written ashttp://<LAN-IP>:5173and the emulator can load assets without certificate trust gymnastics. Production builds are unaffected (assets are bundled into the APK/AAB).Considered shipping a debug
network_security_config.xmlwith<certificates src="user"/>instead, but that still requires every developer to manually export Herd's CA, set a lock-screen PIN on the emulator, push and install the cert via Settings, and repeat for every fresh AVD — strictly worse UX than disabling HTTPS for the dev server.Test plan
php artisan native:run -W androidagainst a fresh emulator.cat public/android-hotshowshttp://<LAN-IP>:5173(nothttps://*.test:5173).php artisan native:run -W iosand confirm iOS still loads assets and HMR.php artisan native:build) and confirm assets are bundled correctly and the hot files are cleaned up.🤖 Generated with Claude Code