It’s very possible I had this issue because I distinctly remember having to switch a project recently from ui-title-bar to s-page, although I don’t remember what my exact issue was as it was with an older project I was updating to web components anyway.
Do you guys keep a set of reference pages in the shopify admin as well as externally so you can monitor for breaking or unexpected changes in the components for both cases?
@Liam-Shopify, Yes. I think there is a compatibility issue with svelte caching and polaris.js
Here is what Gemini said about the adopedStylesheets issue. The code is part
The adopedStylesheets code from Polaris you provided reveals the smoking gun. This isn't just a Svelte issue; it is an architectural conflict between how Polaris (built on Preact/Custom Elements) handles styles and how Svelte/Turbo moves elements around the DOM.
The Source of the Crash
Look at this specific part of the code you shared:
JavaScript
adoptedCallback() {
this.#i(),
this[Je] && (
this[Je].adoptedStyleSheets = [], // 1. Wipes existing styles
je(this[Je], this.#r), // 2. Tries to re-apply global CSS
je(this[Je], this.#a) // 3. Tries to re-apply component CSS
)
}
The function je (defined earlier in your snippet) is trying to use new r (which is new CSSStyleSheet()) and cache it in a WeakMap called Me.
Why the Key didn't fix it: Svelte's {#key} destroys and remounts the component. When that new component is added to the DOM, if it is being moved into a different "Document Context" (common in Svelte's transition/fragment phase), the adoptedCallback fires. Polaris then tries to pull a cached stylesheet from that WeakMap and apply it to a new document. Browsers strictly forbid sharing a Constructed Style Sheet between two different documents for security reasons.
The Fix: Browser Environment Isolation
Since you cannot easily change the Polaris source code, you need to prevent Svelte from "re-adopting" the node in a way that triggers this logic.