Problem/Motivation
Creating a new multi-site or site with settings.php not in docroot/sites/default/ causes aggregated CSS and JS assets to 404 by default. Setting
$settings['file_public_path'] in settings.php to a valid path fixes the problem, but that feels broken that we should have to do that by default when we previously did not.
10.1 has updated CSS/JS aggregation to a lazy method that only generates the files when the resources are requested: https://www.drupal.org/node/2888767.
Tracking down the issue, I see that the dynamic route provider Drupal\System\Routing\AssetRoutes creates a dynamic path using getDirectoryPath() on Drupal\Core\StreamWrapper\AssetStream which in turn calls basePath on Drupal\Core\StreamWrapper\AssetStream. basePath has the following code:
return Settings::get(
'file_assets_path',
Settings::get('file_public_path', 'sites/default/files')
);
This will always default to sites/default/files if $settings['file_public_path'] isn't explicitly set.
AssetStream's parent class PublicStream, however, has a version of basePath that uses the DrupalKernel service to get the site path, and it correctly uses sites.php to find the correct path by default.
$site_path = \Drupal::getContainer()->getParameter('site.path');
I feel like AssetStream should be updated to be closer to PublicStream.
Steps to reproduce
1. Download Drupal 10.1 via composer
2. Create docroot/sites/www folder and copy docroot/sites/default files to new folder.
3. Update docroot/sites/sites.php to point to docroot/sites/www by default.
4. Install Drupal using standard profile.
5. See JS/CSS aggregated files not rendering.
Proposed resolution
Update basePath on AssetStream to be closer to basePath on PublicStream and use the following to get the correct site path if one isn't explicity set in settings.php
$site_path = \Drupal::getContainer()->getParameter('site.path');
Comments
Comment #2
longwaveDoes this also affect multisites that upgrade to 10.1?
Comment #3
catchThis is from #3027639: Make css/js optimized assets path configurable I think.
Comment #4
catchI spotted this after commit and opened a follow-up already, but didn't fully realise the specific context in which it would break - of course it would be multisite (or a single site using a multisite file structure).
One issue should be duplicate - this has better steps to reproduce, the other issue is older, leaving both open for right now.
#3354090: Better default base path in assets stream wrapper.
Comment #5
catchMoved the steps to reproduce over to #3354090: Better default base path in assets stream wrapper which now has a failing test and patch.
Comment #6
cookiejar commentedThis issue seem to be closed with duplicate of some other issues. Just wanted to check if the related issue has been addressed.
I'm noticing related issue in Drupal 10.4. Some details of the issue I see noted on below URL:
https://www.drupal.org/forum/support/post-installation/2025-08-01/reques...