Repository navigation
🐛 Fix @vite asset URLs on multisite subsites - #544
Conversation
|
Thanks for the fix. Could you update this to avoid Ideally rewrite only the stale host, preserve the path/query, and add tests for subdomain + subdirectory multisite |
…multisite and add subdomain/subdirectory tests
|
@retlehs Updated, thank you for the feedback! assetPath() now uses a private rewriteHost() helper that takes only the scheme/host/port from See the changes here:
I also added tests for single-site passthrough, subdomain multisite, and subdirectory multisite. |
Co-authored-by: QWp6t <QWp6t@users.noreply.github.com>
|
Thanks for the updates! This rewrites every host on multisite, so assets served from a CDN or another domain would get rewritten to the subsite host. Could you only rewrite when the asset host matches the main site's host (e.g. The repeated app/config setup in the tests could also be pulled into a helper or dataset Also, are you using Bedrock? Want to confirm this is coming from |
|
Good catch on the CDN case, I hadn't thought of that. It now only swaps the host when the asset lives on the main site's host (parse_url(network_home_url(), PHP_URL_HOST)), and anything else is left as is. I added a test for a CDN URL too, and cleaned up the tests with a small helper and a dataset so they're less repetitive. And yes, we're using Bedrock. |
In a WordPress multisite network, the @Vite directive generates asset tags pointing to the main site's domain instead of the current subsite's domain, causing CORS errors on subsites. This issue has also been discussed on Roots Discourse.
Vite::assetPath() resolves the URI from assets.manifests.*.url, which is set once at boot from get_theme_file_uri() and never reflects the active subsite context.
home_url()returns the correct origin for the currently active site. The fix is scoped tois_multisite()so single-site installs are completely unaffected.