Repository navigation
fix(hydrogen): configure Standard Actions after the deferred script runs - #4372
Open
fredericoo wants to merge 8 commits into
Open
fredericoo wants to merge 8 commits into
fredericoo wants to merge 8 commits into
Conversation
Contributor
|
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
fredericoo
marked this pull request as ready for review
November 12, 2026 20:27
fredericoo
marked this pull request as draft
November 12, 2026 20:42
fredericoo
marked this pull request as ready for review
November 13, 2026 12:19
andguy95
requested changes
Nov 18, 2026
…onfiguring the cart
fredericoo
force-pushed
the
fb-standard-actions-deferred-ready
branch
from
November 19, 2026 12:54
57efba1 to
f0fc6e4
Compare
fredericoo
enabled auto-merge
November 19, 2026 12:54
Contributor
📦 Bundle size report
Unchanged (10)
How this is measuredEach scenario is bundled from the built package with Rolldown (tree-shaken, minified, dynamic imports inlined), then gzipped. Peer dependencies are external. Scenarios live in 🟢 smaller · 🟡 larger (< 5%) · 🔴 larger (≥ 5%) · 🆕 not in base · ❌ failed to bundle · ⚪ unchanged |
fredericoo
marked this pull request as draft
November 19, 2026 12:58
auto-merge was automatically disabled
November 19, 2026 12:58
Pull request was converted to draft
…ter DOMContentLoaded The ready listener runs outside the Promise executor, so a throw from configureUpdateCartOnce escaped as an uncaught error and left the shared promise pending forever. Catch it and reject so the next call retries.
Each connect() attached its own log to the shared readiness promise, so StrictMode remounts and multiple stores logged the same failure several times. Log from the shared promise's catch instead.
…ogger Tests that connect a cart store without caring about Standard Actions now get a minimal window.Shopify.actions stub, so the setup error isn't produced at all and the real logger stays in place. Tests that exercise a failed setup inject a test logger and assert the log.
…ard Actions script Deferred scripts always run before DOMContentLoaded, so by window load the server-rendered tag has already failed. Drop the resolve-at-load test case, which covered late-injected tags that are out of scope.
fredericoo
marked this pull request as ready for review
November 19, 2026 13:58
This branch has not been deployed
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.
Closes #4332
TL;DR: The cart store can try to configure Standard Actions after HTML parsing finishes but before
standard-actions.jshas run. The attempt fails silently and isn't retried, so directwindow.Shopify.actions.updateCartcalls go to Shopify's default handler instead of the endpoint set withconfigureCartEndpoint().This is a smaller alternative to #4337, which fixes the same race with a load/error/timeout state machine.
Before
ShopifyScriptsrendersstandard-actions.jsas<script type="module">with noasync, so the browser defers it. The order on page load is:document.readyStatebecomes"interactive"standard-actions.jsDOMContentLoadedfiresgetShopifyStandardActions()only waited whilereadyState === "loading". The app entry is anasyncmodule, so on a slow connection it can hydrate between steps 1 and 2. When it does,CartProviderconnects the store beforewindow.Shopify.actionsexists, setup rejects, andconnectCartStoreswallows the error.After
While the document is
"interactive"and the actions aren't there yet, Hydrogen waits forDOMContentLoadedor windowload, whichever fires first, and then configures as before.DOMContentLoadedis the fast path: it fires right after deferred scripts run.loadcovers the case whereDOMContentLoadedalready fired. By then the deferred script has either run or failed.What this changes
getShopifyStandardActions(), plus cleaning up both listeners with anAbortController.connectCartStorenow logs setup failures withlog.errorinstead of swallowing them. Before, this bug left no trace.Developer impact
Includes a patch changeset for
@shopify/hydrogen. No public API changes. Storefronts without a working Standard Actions script now get a[hydrogen:error:cart] standard actions setup failedlog through the default logger.Out of scope
maindoesn't support either. Apps that useShopifyScriptsrender the tag in the server HTML.DOMContentLoaded/loadrather than straight away.Risk
DOMContentLoadedhas already fired, the rejection now waits for windowload, which can be slow on pages with lots of images. Cart actions fail in that case anyway, so only the time until the error changes.asyncscript, and neithermainnor this PR handles that.