diff --git a/core/lib/Drupal/Core/Asset/AssetGroupSetHashTrait.php b/core/lib/Drupal/Core/Asset/AssetGroupSetHashTrait.php index 1d805b4c32..660d1a12a9 100644 --- a/core/lib/Drupal/Core/Asset/AssetGroupSetHashTrait.php +++ b/core/lib/Drupal/Core/Asset/AssetGroupSetHashTrait.php @@ -36,6 +36,12 @@ protected function generateHash(array $group): string { ]; foreach ($group['items'] as $key => $asset) { $normalized['asset_group']['items'][$key] = array_diff_key($asset, $group_keys, $omit_keys); + // If the version is set to -1, this means there is no version in the + // library definition. To ensure unique hashes when unversioned files + // change, replace the version with a hash of the file contents. + if ($asset['version'] === -1) { + $normalized['asset_group']['items'][$key]['version'] = hash('xxh64', file_get_contents($asset['data'])); + } } // The asset array ensures that a valid hash can only be generated via the // same code base. Additionally use the hash salt to ensure that hashes are