diff --git a/CHANGELOG.md b/CHANGELOG.md index fa356285b..17120547d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ * Fixed save error when editing accounts that have been created with capital letters in their username [#3211](https://github.com/getgrav/grav/issues/3211) * Fixed renaming flex objects key when using file storage * Fixed wrong values in Admin pages list [#3214](https://github.com/getgrav/grav/issues/3214) + * Fixed pipelined asset using different hash when extra asset is added to before/after position [#2781](https://github.com/getgrav/grav/issues/2781) # v1.7.5 ## 02/01/2021 diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index bc2c66f87..7b51973fe 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -92,6 +92,8 @@ class Assets extends PropertyObject protected $collections; /** @var string */ protected $timestamp; + /** @var array Keeping track for order counts (for sorting) */ + protected $order = []; /** * Initialization called in the Grav lifecycle to initialize the Assets with appropriate configuration @@ -232,7 +234,15 @@ class Assets extends PropertyObject $options['timestamp'] = $this->timestamp; // Set order - $options['order'] = count($this->$collection); + $group = $options['group'] ?? 'head'; + $position = $options['position'] ?? 'pipeline'; + + $orderKey = "{$type}|{$group}|{$position}"; + if (!isset($this->order[$orderKey])) { + $this->order[$orderKey] = 0; + } + + $options['order'] = ++$this->order[$orderKey]; // Create asset of correct type $asset_object = new $type(); diff --git a/system/src/Grav/Common/Assets/Traits/TestingAssetsTrait.php b/system/src/Grav/Common/Assets/Traits/TestingAssetsTrait.php index 11604dd63..cb8de18ae 100644 --- a/system/src/Grav/Common/Assets/Traits/TestingAssetsTrait.php +++ b/system/src/Grav/Common/Assets/Traits/TestingAssetsTrait.php @@ -189,6 +189,7 @@ trait TestingAssetsTrait $this->resetJs(); $this->setCssPipeline(false); $this->setJsPipeline(false); + $this->order = []; return $this; }