From 34b179f0b3b63b9c2caaf4ae0350747cdfacddc4 Mon Sep 17 00:00:00 2001 From: Chris Huber Date: Mon, 16 Nov 2026 00:23:10 +0000 Subject: [PATCH] fix: preserve header ownership without promoting navigation-only variants --- .../src/WordPressSitePlan/ShellExtraction.php | 45 ++++++++++++++----- .../unanchored-header-layout-variant.php | 30 +++++++++++++ ...unanchored-header-navigation-exclusion.php | 30 +++++++++++++ 3 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 php-transformer/tests/contract/unanchored-header-layout-variant.php create mode 100644 php-transformer/tests/contract/unanchored-header-navigation-exclusion.php diff --git a/php-transformer/src/WordPressSitePlan/ShellExtraction.php b/php-transformer/src/WordPressSitePlan/ShellExtraction.php index 8f5793f89..bae6ee57c 100644 --- a/php-transformer/src/WordPressSitePlan/ShellExtraction.php +++ b/php-transformer/src/WordPressSitePlan/ShellExtraction.php @@ -2052,18 +2052,22 @@ public function sharedShells(array $pages, array $reservedSlugs = array(), array } // A shared landmark can have route-local presentation. Keep those // variants editable without substituting the dominant route's paint. - // A matching source anchor proves shell ownership; unrelated article - // headers and unlabelled route content must not be promoted. + // A matching source anchor or authored landmark wrapper proves shell + // ownership; unrelated article headers must not be promoted. foreach ($parts as $part) { if ('header' !== ($part['area'] ?? null)) continue; $partIndex = new \Automattic\BlocksEngine\PhpTransformer\Support\BlockMarkupIndex($part['canonical_block_markup']); $anchors = array(); + $wrappers = array(); foreach ($partIndex->tokens() as $token) { if ($token['closing']) continue; $attrs = json_decode($token['attributes'], true); - if ('header' === ($attrs['tagName'] ?? null) && !empty($attrs['anchor'])) $anchors[$attrs['anchor']] = array($attrs['style'] ?? array(), $attrs['className'] ?? ''); + if ('header' !== ($attrs['tagName'] ?? null)) continue; + $wrapper = array($attrs['style'] ?? array(), $attrs['className'] ?? ''); + if (!empty($attrs['anchor'])) $anchors[$attrs['anchor']] = $wrapper; + elseif (!empty($attrs['className'])) $wrappers[] = $wrapper; } - if (array() === $anchors) continue; + if (array() === $anchors && array() === $wrappers) continue; foreach ($pages as $index => $page) { // Do not promote a second occurrence on a route that already // contributed its shell, or one retained for unsafe placement. @@ -2075,18 +2079,29 @@ public function sharedShells(array $pages, array $reservedSlugs = array(), array $row = $rows[0]; $tokens = (new \Automattic\BlocksEngine\PhpTransformer\Support\BlockMarkupIndex($row['markup']))->tokens(); $attrs = json_decode($tokens[0]['attributes'] ?? '', true); - if (!isset($anchors[$attrs['anchor'] ?? ''])) continue; - // Descendant paint and navigation selection remain route-owned. - // Layout differences, however, can describe a distinct shell - // even when its landmark wrapper has identical attributes. - if (array($attrs['style'] ?? array(), $attrs['className'] ?? '') === $anchors[$attrs['anchor']] - && self::descendantShellLayout($row['markup']) === self::descendantShellLayout($part['canonical_block_markup'])) continue; + $wrapper = array($attrs['style'] ?? array(), $attrs['className'] ?? ''); + $sharedWrapper = $anchors[$attrs['anchor'] ?? ''] ?? null; + // An unanchored landmark can still prove route-shell ownership + // through the same authored wrapper and copy. Keep its layout + // in a route-local part rather than freezing the donor's paint. + if (null === $sharedWrapper && empty($attrs['anchor']) && in_array($wrapper, $wrappers, true)) $sharedWrapper = $wrapper; + if (null === $sharedWrapper) continue; + // Navigation-only exclusions remain route-owned unless layout + // differs. A bound control, however, must move with its shell + // into an editable part, even when block layout is identical. if (self::textRuns($row['markup']) !== self::textRuns($part['canonical_block_markup'])) continue; $bindings = $this->runtimeBindingsInRanges($runtimeDeclarations, $page, array($row)); - if ($bindings['blocked'] || array() !== $bindings['refs']) continue; + if ($bindings['blocked']) continue; + if ((!empty($attrs['anchor']) || (array() === $bindings['refs'] && str_contains($row['markup'], '