Fix: Clear products cache on locale override to prevent stale pricing#6451
Fix: Clear products cache on locale override to prevent stale pricing#6451facumenzella wants to merge 2 commits intomainfrom
Conversation
When `overridePreferredUILocale` was called, only the offerings cache was cleared. The products cache in `CachingProductsManager` retained stale StoreKit products keyed by product ID, so re-fetched offerings would still resolve to the old currency/pricing. This caused users (e.g., Canadian storefront) to see USD prices instead of CAD. Now `productsManager.clearCache()` is called alongside the offerings cache invalidation, matching the behavior of `handleStorefrontChange()`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ajpallares
left a comment
There was a problem hiding this comment.
Makes sense! Thanks for fixing!
Seems this wouldn't fix the issue after all?
StoreKit product prices (price, currencyCode, localizedPriceString) are determined by the user's App Store storefront (tied to their Apple ID region), not by the SDK's preferred locale override. Calling overridePreferredUILocale changes which paywall localization text is selected, but it doesn't change what StoreKit returns for product data.
The existing code already re-fetches offerings from the backend (which picks up the new locale for paywall content), but the StoreKit products themselves will be identical regardless of locale. So productsManager.clearCache() here just forces an unnecessary re-fetch from StoreKit that returns the same data.
The handleStorefrontChange() pattern clears the products cache because storefront changes actually change StoreKit pricing. That scenario is different from a locale override. If there's a real bug on the SDK, I'd say the root cause is likely elsewhere.
|
@ajpallares do you want to take another look? let's see if we can merge this one too |
@facumenzella Are we even sure that this would fix the issue? I ask because of my comment above. That said, I don't think this change would harm, so I'm not blocking the merge |
|
Let's close this one because it won't actually solve it |
Summary
overridePreferredUILocalewas called, only the in-memory offerings cache was cleared — theCachingProductsManagerproduct cache was notproductsManager.clearCache()is called alongside the offerings cache invalidation, matching the existing behavior ofhandleStorefrontChange()Test plan
testOverridePreferredUILocaleClearsProductsCachethat verifiesproductsManager.clearCache()is calledoverridePreferredUILocaletests pass (6/6)overridePreferredUILocaleafter initial load with a different storefront and confirm correct currency is displayed🤖 Generated with Claude Code
Note
Low Risk
Low risk: small, targeted cache invalidation change gated by existing rate limiting; main risk is extra product refetches after locale changes.
Overview
Ensures
overridePreferredUILocalefully refreshes locale-dependent pricing by clearing the products cache (productsManager.clearCache()) in addition to invalidating in-memory offerings before refetching offerings.Adds a unit test (
testOverridePreferredUILocaleClearsProductsCache) to verify the products cache is cleared when the preferred UI locale changes.Reviewed by Cursor Bugbot for commit 585c9d8. Bugbot is set up for automated code reviews on this repo. Configure here.