@shopify/partial-rendering fails to load in Firefox: import map is output after module scripts in content_for_header

Short description of issue

In Firefox, importing “@shopify/partial-rendering” fails because the import map in content_for_header is output after several Shopify module scripts, so Firefox ignores it. Chrome and Safari are not affected.

Reproduction steps

  1. On a development store, add a section containing:
    <script type="module">
      const { partials } = await import('@shopify/partial-rendering');
      console.log(partials.getAll());
    </script>
    
  2. Open the page in Chrome or Safari: the package loads and partials.refresh('partials-test') works.
  3. Open the same page in Firefox 158 (macOS): the import fails with:
    The specifier "@shopify/partial-rendering" was a bare specifier, but was not remapped to anything. Relative module specifiers must start with "./", "../" or "/".
  4. Inspect the order of module-related elements in the DOM: the <script type="importmap"> comes after several module scripts that content_for_header outputs itself.

Additional info

In content_for_header, the importmap is output after Shopify’s own module scripts (shop-js):

… [head] module  inline: (o.Shopify=o.Shopify||{}).modules=!0
… [head] module  shopifycloud/shop-js/modules/v2/loader.init-shop-cart-sync.fr.esm.js
… [head] module  inline: await import("…/shop-js/…")
… [head] importmap  {"imports":{"@shopify/partial-rendering":"…"}}

Firefox ignores an import map that appears after module loading has started (Chrome/Safari merge it). Moving content_for_header above the theme scripts doesn’t help, since these modules come from content_for_header itself.

Expected: output the importmap first in content_for_header.

Workaround: import the URL read from the import map directly (works in Firefox, but bypasses its integrity check).

What type of topic is this

Bug report

Hi @MaxX, thanks for sharing the reproduction steps and flagging the integrity concern with the workaround. I’ve asked our team to review the Firefox behavior you’re seeing.

I’ll follow up here when I have an update.