Skip to content

Fix: Clear products cache on locale override to prevent stale pricing#6451

Closed
facumenzella wants to merge 2 commits intomainfrom
fix/clear-products-cache-on-locale-override
Closed

Fix: Clear products cache on locale override to prevent stale pricing#6451
facumenzella wants to merge 2 commits intomainfrom
fix/clear-products-cache-on-locale-override

Conversation

@facumenzella
Copy link
Copy Markdown
Member

@facumenzella facumenzella commented Mar 12, 2026

Summary

  • When overridePreferredUILocale was called, only the in-memory offerings cache was cleared — the CachingProductsManager product cache was not
  • This meant re-fetched offerings would resolve to stale cached StoreKit products with the old currency/pricing (e.g., USD instead of CAD for Canadian users)
  • Now productsManager.clearCache() is called alongside the offerings cache invalidation, matching the existing behavior of handleStorefrontChange()

Test plan

  • Added testOverridePreferredUILocaleClearsProductsCache that verifies productsManager.clearCache() is called
  • All existing overridePreferredUILocale tests pass (6/6)
  • Manual verification: call overridePreferredUILocale after 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 overridePreferredUILocale fully 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.

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>
@facumenzella facumenzella requested a review from a team as a code owner March 12, 2026 13:32
ajpallares
ajpallares previously approved these changes Mar 12, 2026
Copy link
Copy Markdown
Member

@ajpallares ajpallares left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Thanks for fixing!

@ajpallares ajpallares dismissed their stale review March 12, 2026 14:19

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.

@facumenzella facumenzella requested a review from a team as a code owner April 23, 2026 12:47
@facumenzella
Copy link
Copy Markdown
Member Author

@ajpallares do you want to take another look? let's see if we can merge this one too

@ajpallares
Copy link
Copy Markdown
Member

@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

@facumenzella
Copy link
Copy Markdown
Member Author

Let's close this one because it won't actually solve it

@facumenzella facumenzella deleted the fix/clear-products-cache-on-locale-override branch April 23, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants