-
-
Notifications
You must be signed in to change notification settings - Fork 268
refactor(ramps-controller): store full region objects in userRegion #7646
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
Conversation
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.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
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.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
| // This ensures that once a region is set (either via geolocation or manual selection), | ||
| // it will not be overwritten by subsequent geolocation fetches. | ||
| if (this.state.userRegion && !options?.forceRefresh) { | ||
| return this.state.userRegion; |
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.
Missing migration for persisted string userRegion causes silent failures
High Severity
Since userRegion has persist: true, users upgrading from a previous version where userRegion was a string will have that string loaded into state. The truthiness check at line 521 passes for a string like "us", causing updateUserRegion() to return the string directly instead of a UserRegion object. Subsequently, all userRegion?.regionCode accesses return undefined (strings lack this property), causing the userRegionCode === undefined checks in updateEligibility and getTokens to always pass, leading to incorrect state updates regardless of the actual region.
Explanation
Refactors
userRegionstate inRampsControllerto store fullCountryandStateobjects instead of just the region code string.Changes
userRegionfromstring | nulltoUserRegion | nullUserRegiontype contains:country: Country- Full country objectstate: State | null- State object if applicable, null otherwiseregionCode: string- Normalized region code (e.g., "us-ut", "fr")setUserRegion()andupdateUserRegion()to fetch countries and find matching Country/State objectsuserRegion.regionCodefor API callsUserRegiontype for consumersregionCodeis normalized at creationBenefits
country.phone.template) without re-parsing region codesBreaking Changes
The
userRegionvariable name remains the same but the type changed fromstringtoUserRegion.References
Checklist
Note
Introduces structured region handling in RampsController.
userRegionnow stores aUserRegionobject (country,state|null,regionCode); access code viauserRegion.regionCode. ExportsUserRegion.updateUserRegion()/setUserRegion()to fetchgetCountries(), map codes toCountry/State, avoid overwriting existing region unlessforceRefresh, and cleartokenson region change. Adds robust handling for missing/failed geolocation/countries/eligibility.findRegionFromCode()helper; updatesinit()to skip geolocation when region already set and to fetch tokens usingregionCode.updateEligibility()/getTokens()to useuserRegion.regionCodeand guard state updates by current region; expands tests for caching, race conditions, and error cases.Written by Cursor Bugbot for commit eda30d6. This will update automatically on new commits. Configure here.