Fix BuyNowButton disabled prop being silently ignored#3691
Fix BuyNowButton disabled prop being silently ignored#3691J8118 wants to merge 2 commits intoShopify:mainfrom
Conversation
|
good spot - since `loading` is `useState(false)`, it's always a boolean and `??` never falls through. the consumer's `disabled` prop was being silently ignored. this is a behavioural change though - consumers passing `disabled={true}` will now have it respected when `loading` is `false`. could you add a changeset? since this touches `hydrogen-react`, it also needs a companion hydrogen bump (hydrogen re-exports everything from hydrogen-react): ```md"@shopify/hydrogen-react": patch
|
|
Done — just pushed the changeset with the hydrogen-react + hydrogen bump |
The nullish coalescing operator (??) was used with the loading boolean, which is always true or false (never null/undefined). This meant the consumer's disabled prop was never evaluated. Changed to logical OR (||) so the button is disabled when either loading or explicitly disabled by the consumer.
1999702 to
7442849
Compare
Summary
In
BuyNowButton.tsxline 69, thedisabledattribute uses??(nullish coalescing) withloadingon the left side:Since
loadingis a boolean (alwaystrueorfalse, nevernullorundefined), the right side is never evaluated. The consumer'sdisabledprop is silently ignored. Compare this toAddToCartButtonwhich correctly combines conditions with||.File changed:
packages/hydrogen-react/src/BuyNowButton.tsx(line 69)Before:
After: