Rocket Logo Rocket Docs Themes Tools Blog

Cross Browser

If we are using server side rendering for any of our web components then you are using declarative shadow dom. As it's not yet fully supported by all browsers, we may want to use a polyfill to make it work.

If we are using an existing theme/preset then it's most likely taken care of for us. If not then we can add this style tag and two script tags to our layout.

npm i -D @webcomponents/template-shadowroot
<!DOCTYPE html>
    <!-- On browsers that don't yet support native declarative shadow DOM, a
         paint can occur after some or all pre-rendered HTML has been parsed,
         but before the declarative shadow DOM polyfill has taken effect. This
         paint is undesirable because it won't include any component shadow DOM.
         To prevent layout shifts that can result from this render, we use a
         "dsd-pending" attribute to ensure we only paint after we know
         shadow DOM is active. -->
      body[dsd-pending] {
        display: none;

  <body dsd-pending>
      if (HTMLTemplateElement.prototype.hasOwnProperty('shadowRoot')) {
        // This browser has native declarative shadow DOM support, so we can
        // allow painting immediately.

    <!-- The pre-rendered web components -->

    <script type="module">
      (async () => {
        // Check if we require the declarative shadow DOM polyfill. As of
        // February 2022, Chrome and Edge have native support, but Firefox
        // and Safari don't yet.
        if (!HTMLTemplateElement.prototype.hasOwnProperty('shadowRoot')) {
          // Fetch the declarative shadow DOM polyfill.
          const { hydrateShadowRoots } = await import(

          // Apply the polyfill. This is a one-shot operation, so it is important
          // it happens after all HTML has been parsed.

          // At this point, browsers without native declarative shadow DOM
          // support can paint the initial state of your components!

This loading strategy is based on the eleventy-plugin-lit bootup strategy.