From 5905ab4d2d987123abb530435f643586edcb6d95 Mon Sep 17 00:00:00 2001 From: Jakub Winkler Date: Wed, 7 Jan 2026 07:43:43 +0100 Subject: [PATCH] fixing setup:di:compile area order in plugin generation so frontend area cache picks up compiled files instead of regenerating on the first request --- .../Interception/PluginList/PluginList.php | 5 ++++- .../Framework/Interception/PluginListGenerator.php | 13 ++++++++++--- .../Di/App/Task/Operation/PluginListGenerator.php | 8 ++------ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php index 6e1d2111dba00..626d5c412e6e8 100644 --- a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php +++ b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php @@ -217,7 +217,10 @@ protected function _loadScopedData() } $this->_scopePriorityScheme[] = $scope; - $cacheId = implode('|', $this->_scopePriorityScheme) . "|" . $this->_cacheId; + // Normalize cache ID by sorting scopes - ensures consistent ID regardless of processing order + $sortedScheme = array_values($this->_scopePriorityScheme); + sort($sortedScheme); + $cacheId = implode('|', $sortedScheme) . "|" . $this->_cacheId; $configData = $this->configLoader->load($cacheId); if ($configData) { diff --git a/lib/internal/Magento/Framework/Interception/PluginListGenerator.php b/lib/internal/Magento/Framework/Interception/PluginListGenerator.php index 0153ee92a8062..426674b3b41b7 100644 --- a/lib/internal/Magento/Framework/Interception/PluginListGenerator.php +++ b/lib/internal/Magento/Framework/Interception/PluginListGenerator.php @@ -90,10 +90,17 @@ public function write(array $scopes): void foreach ($scopes as $scope) { $this->scopeConfig->setCurrentScope($scope); if (false === isset($this->loadedScopes[$scope])) { - if (false === in_array($scope, $this->scopePriorityScheme, true)) { - $this->scopePriorityScheme[] = $scope; + // Match PluginList::_loadScopedData() behavior - move scope to end + // This ensures cache IDs match between compile-time and runtime + $index = array_search($scope, $this->scopePriorityScheme, true); + if ($index !== false) { + unset($this->scopePriorityScheme[$index]); } - $cacheId = implode('|', $this->scopePriorityScheme) . "|" . $this->cacheId; + $this->scopePriorityScheme[] = $scope; + // Normalize cache ID by sorting scopes - ensures consistent ID regardless of processing order + $sortedScheme = array_values($this->scopePriorityScheme); + sort($sortedScheme); + $cacheId = implode('|', $sortedScheme) . "|" . $this->cacheId; [ $virtualTypes, $this->scopePriorityScheme, diff --git a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php index 63db48bc7d9d2..fb6d433760f1a 100644 --- a/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php +++ b/setup/src/Magento/Setup/Module/Di/App/Task/Operation/PluginListGenerator.php @@ -44,12 +44,8 @@ public function __construct( public function doOperation() { $scopes = $this->scopeConfig->getAllScopes(); - // remove primary scope for production mode as it is only called in developer mode - $scopes = array_diff($scopes, ['primary']); - - // sort configuration to have it in the same order on every build - ksort($scopes); - + // Cache IDs are now normalized (sorted) in PluginListGenerator::write() + // so processing order no longer affects cache ID generation $this->configWriter->write($scopes); }