From 27c9a74bca1bd84728724bfbc4b695358ff9da66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Bajsarowicz?= Date: Wed, 4 Feb 2026 00:07:05 +0100 Subject: [PATCH] fix(framework): normalize plugin list cache ID generation Sort scopes alphabetically before creating cache IDs to ensure consistency between compile-time (PluginListGenerator) and runtime (PluginList) generation. This allows pre-compiled plugin metadata files to be loaded correctly, improving performance after cache:flush. Fixes magento/magento2#40407 --- .../Framework/Interception/PluginList/PluginList.php | 6 +++++- .../Magento/Framework/Interception/PluginListGenerator.php | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php index 2f86c8703dea5..3553e29f8a76b 100644 --- a/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php +++ b/lib/internal/Magento/Framework/Interception/PluginList/PluginList.php @@ -217,7 +217,11 @@ protected function _loadScopedData() } $this->_scopePriorityScheme[] = $scope; - $cacheId = implode('|', $this->_scopePriorityScheme) . "|" . $this->_cacheId; + // Sort scopes alphabetically to ensure cache ID is deterministic + // regardless of processing order (fixes mismatch with compile-time generation) + $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..c7d9ccdd1f17c 100644 --- a/lib/internal/Magento/Framework/Interception/PluginListGenerator.php +++ b/lib/internal/Magento/Framework/Interception/PluginListGenerator.php @@ -93,7 +93,11 @@ public function write(array $scopes): void if (false === in_array($scope, $this->scopePriorityScheme, true)) { $this->scopePriorityScheme[] = $scope; } - $cacheId = implode('|', $this->scopePriorityScheme) . "|" . $this->cacheId; + // Sort scopes alphabetically to ensure cache ID is deterministic + // regardless of processing order (fixes mismatch with runtime loading) + $sortedScheme = array_values($this->scopePriorityScheme); + sort($sortedScheme); + $cacheId = implode('|', $sortedScheme) . "|" . $this->cacheId; [ $virtualTypes, $this->scopePriorityScheme,