onMount method
Called when the component is mounted/hydrated in the browser.
Override this method to add interactivity to your component. The shadow DOM will already be rendered (thanks to Declarative Shadow DOM).
Implementation
@override
void onMount() {
super.onMount();
// Apply adopted stylesheets if defined (for browser efficiency)
final styles = adoptedStyleSheets;
if (styles != null) {
adoptStyleSheets([styles.toCss()]);
// Remove the SSR-rendered <style> element since adoptedStyleSheets now handles styles.
// This also ensures update() can patch correctly without the style element offset.
final root = shadowRoot;
if (root != null) {
final firstChild = root.firstElementChild;
if (firstChild != null && firstChild.tagName.toLowerCase() == 'style') {
firstChild.remove();
}
}
}
update();
}