From 5c596ba2ecc98a947ff90b3366ab81b905abaa32 Mon Sep 17 00:00:00 2001 From: Oto Macenauer Date: Thu, 24 Sep 2026 17:03:38 +0200 Subject: [PATCH 1/2] fix: run router-swapped sub-app scripts in the fragment, not the host reframed runs a fragment script in its iframe only when the script reaches the fragment's DOM through a host-realm insertion method: it patches the host window's Node/Element prototypes and nothing else. The ClientRouter parses the fetched page in the iframe, so its nodes are iframe-realm, and Astro's post-swap `script.replaceWith(fresh)` resolved to the iframe's unpatched replaceWith. Every sub-app script swapped in by a navigation executed in the HOST window: a vendored mermaid bundle defined window.mermaid on the host page, the init script found no diagrams there, and the flowchart stayed source text. A hard load was unaffected, which is why only in-fragment navigation showed it. The embedded swap now imports the fetched head and body into the host document before swapping them in. data-astro-exec marks survive the copy, so scripts already running are not run twice. Also moves the shadow-DOM design tokens ahead of the page content. They came last in , so a blocking