onHydrating method

  1. @override
void onHydrating()
override

Called during hydration, before initial attributes are notified.

Override this to perform setup steps that must happen before the first attributeChangedCallback (and subsequent update) occurs.

Implementation

@override
void onHydrating() {
  // 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.
    final root = shadowRoot;
    if (root != null) {
      final firstChild = root.firstElementChild;
      // Check for style tag
      if (firstChild != null && firstChild.tagName.toLowerCase() == 'style') {
        firstChild.remove();
      }
    }
  }
}