fix(web-components): load both web-components.js AND account.js bundles#386
Merged
Merged
Conversation
The header's <ShopifyAccountButton> renders <shopify-account> nested
inside <shopify-store>, but only the account bundle was loaded. The
account bundle does not register <shopify-store> synchronously \u2014 it
dynamic-imports a chunked store-*.js whose execution arrives AFTER
<shopify-account>'s connectedCallback fires, emitting on every page
load:
[shopify-account] <shopify-store> custom element is not registered.
Ensure the storefront-components bundle is loaded so
<shopify-account> can fetch data.
Verified bundle map by fetching each bundle and tracing the
registration helper (calls customElements.define via template literal
`shopify-${t}`, so literal-string grep misses them):
web-components.js (92KB)
shopify-store, shopify-cart, shopify-catalog, shopify-context,
shopify-data, shopify-list-context, shopify-media, shopify-money,
shopify-variant-selector
web-components/account.js (31KB)
shopify-account, shopify-customer-account-data, shopify-render,
shopify-element-wrapper
(NB: does NOT register shopify-store synchronously)
Fix: load BOTH bundles in document order. Switch from async to defer \u2014
module scripts are deferred by default and execute in declaration
order with defer, which is required (if account.js runs before
web-components.js, the same warning fires).
hta218
approved these changes
May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add the
web-components.jsscript tag alongsideweb-components/account.jsinapp/root.tsx. Switch both fromasynctodeferso they execute in document order.Why
The header's
<ShopifyAccountButton>renders<shopify-account>nested inside<shopify-store>, but only the account bundle was loaded, producing this console warning on every page load and rendering the empty<span slot="signed-out-avatar">fallback instead of the account widget:Bundle analysis (verified by fetching + tracing both bundles)
customElements.defineuses template-literal interpolation\shopify-${t}`, so literal-string grep for"shopify-store"misses the registrations. Tracing the registration helperI(name, ctor)` reveals:cdn.shopify.com/storefront/web-components.jsshopify-store,shopify-cart,shopify-catalog,shopify-context,shopify-data,shopify-list-context,shopify-media,shopify-money,shopify-variant-selectorcdn.shopify.com/storefront/web-components/account.jsshopify-account,shopify-customer-account-data,shopify-render,shopify-element-wrapperThe account bundle DOES dynamic-import a chunked
./account/store-*.js(visible in the bundle source as the lastimport()call), but the chunk arrives after<shopify-account>'sconnectedCallbackruns, hitting a race. The connectedCallback callscustomElements.get("shopify-store"), finds nothing, emits the warning, and bails.This corrects my earlier (closed) PR #385 which claimed
web-components.jswas an umbrella superset \u2014 it isn't. The two bundles are disjoint feature sets, and<shopify-account>inside<shopify-store>needs both.Why
deferinstead ofasyncModule scripts are deferred by default. Both
deferand the implicit deferred behaviour of module scripts preserve document order at execution time.asyncdoes NOT preserve order \u2014 ifaccount.jshappens to finish downloading first and executes beforeweb-components.js, the same warning fires. The explicitdeferis belt-and-suspenders to encode the intent.Behaviour change
<shopify-account>connectedCallback warning on every page render. Login widget shows the slot-provided<UserIcon>fallback indefinitely; user can't see signed-in avatar or account dropdown.<shopify-store>is registered first, then<shopify-account>finds its parent on connectedCallback and renders the full account widget.Verification
[shopify-account] <shopify-store> custom element is not registeredwarning should be absent.<UserIcon>fallback.Net bundle cost
+92 KB gzipped (one new module script). Negligible on the critical path because both scripts are
defer\u2014 they don't block HTML parsing or initial render. Net: a one-time cost for the warning to go away and the account widget to actually work.