Skip to content

Create the storefront client on first use - #373

Merged
ryanmitchell merged 2 commits into
statamic-rad-pack:mainfrom
lwekuiper:fix/lazy-storefront-client
Sep 22, 2026
Merged

ryanmitchell merged 2 commits into
statamic-rad-pack:mainfrom
lwekuiper:fix/lazy-storefront-client

Conversation

@lwekuiper

Copy link
Copy Markdown
Contributor

client.js calls createStorefrontApiClient() at module load and reads window.shopifyConfig.url directly. On any page that does not output {{ shopify:tokens }}, that throws a TypeError while the module graph is evaluating, which takes down the whole bundle, not just the cart. On a site where the shop is one section of a larger Statamic site, that means the nav, modals and everything else stop working on pages unrelated to the shop.

Moving the construction into request() keeps the same default export and the same call sites (only client.request() is used in cart.js), but a page without the tokens tag now simply never constructs a client.

@ryanmitchell

Copy link
Copy Markdown
Contributor

Great idea, thank you

@ryanmitchell
ryanmitchell merged commit 5076278 into statamic-rad-pack:main Sep 22, 2026
6 checks passed
@lwekuiper
lwekuiper deleted the fix/lazy-storefront-client branch September 22, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants