From 02d037fbb2e48128f425c63b72cd80f0e91e2c7f Mon Sep 17 00:00:00 2001 From: Chris Huber Date: Sun, 26 Jul 2026 20:37:50 -0400 Subject: [PATCH] Preserve runtime-targeted anchors --- .../Support/ButtonLinkDispatchTrait.php | 4 ++++ php-transformer/tests/contract/run.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/php-transformer/src/HtmlToBlocks/Support/ButtonLinkDispatchTrait.php b/php-transformer/src/HtmlToBlocks/Support/ButtonLinkDispatchTrait.php index b1b2e78e..aa4eec0c 100644 --- a/php-transformer/src/HtmlToBlocks/Support/ButtonLinkDispatchTrait.php +++ b/php-transformer/src/HtmlToBlocks/Support/ButtonLinkDispatchTrait.php @@ -13,6 +13,10 @@ trait ButtonLinkDispatchTrait */ private function convertAnchorDispatchElement(DOMElement $element, array &$fallbacks): ?array { + if ( $this->isRuntimeDomTarget($element) ) { + return $this->htmlPreservationBlock($element); + } + $linkedLogo = $this->linkedSvgLogoBlockFromAnchor($element, $fallbacks); if ( null !== $linkedLogo ) { return $linkedLogo; diff --git a/php-transformer/tests/contract/run.php b/php-transformer/tests/contract/run.php index 0ef48f8d..179ce3e6 100644 --- a/php-transformer/tests/contract/run.php +++ b/php-transformer/tests/contract/run.php @@ -842,6 +842,20 @@ public function match(DOMElement $element, PatternContext $context): ?array $assert(str_contains((string) ($artifactControlIslands[0]['source_snippet'] ?? ''), 'compile( + array( + 'entrypoint' => 'index.html', + 'files' => array( + 'index.html' => '
', + 'js/app.js' => 'document.querySelectorAll(".event-add").forEach(function (link) { link.addEventListener("click", function (event) { event.preventDefault(); }); });', + ), + ) +)->toArray(); +$artifactRuntimeAnchorMarkup = (string) ($artifactRuntimeAnchor['serialized_blocks'] ?? ''); +$artifactRuntimeAnchorIslands = $artifactRuntimeAnchor['source_reports']['runtime_islands'] ?? array(); +$assert(str_contains($artifactRuntimeAnchorMarkup, '