Skip to content
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: incorrect locale caching in message formatter #251

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

michelheusschen
Copy link

The getMessageFormatter function calls monadicMemoize with a function that takes 2 parameters: message and locale. However, monadicMemoize only uses the first parameter for the cache key. This causes an issue when getMessageFormatter is called with the same message but a different locale:

// Correctly outputs 10,000
getMessageFormatter('{count, number} pages', 'en').format({ count: 10_000 })

// Incorrectly outputs 10,000 (expected 10.000)
getMessageFormatter('{count, number} pages', 'nl').format({ count: 10_000 })

Changes:

  • Modify getMessageFormatter to call monadicMemoize with only one parameter
  • Change the type of monadicMemoize to only accept one parameter to prevent recurrence
  • Add unit tests to verify this scenario works correctly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant