-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix getProductOption
from crashing when one of the optionValues doesn't return a firstSelectableVariant
#2704
Conversation
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
firstSelectableVariant
firstSelectableVariant
getProductOption
from crashing when one of the optionValues doesn't return a firstSelectableVariant
// It is possible for firstSelectableVariant to be null | ||
firstOptionValues = product.options[0].optionValues.filter( | ||
(value) => !!value?.firstSelectableVariant, | ||
)[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should happen before the above !firstOptionValues?.name
check, otherwise we're potentially ending up with an option value without a name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
firstOptionValues
is assigned as the first item in product.options[0].optionValues
on line 236
Line 243-246 is just reassigning firstOptionValues
to ensure it returns an option value that has a firstSelectableVariant
defined
WHY are these changes introduced?
Fixes #2698
On a very rare occasion,
optionValues.firstSelectableVariant
may returnnull
.WHAT is this pull request doing?
Make sure
getProductOption
handles well if encountered a nullfirstSelectableVariant
.HOW to test your changes?
Post-merge steps
Checklist