Skip to content

fix: incorrect locale caching in message formatter#251

Open
michelheusschen wants to merge 1 commit intokaisermann:mainfrom
michelheusschen:fix/caching-locale-message-formatter
Open

fix: incorrect locale caching in message formatter#251
michelheusschen wants to merge 1 commit intokaisermann:mainfrom
michelheusschen:fix/caching-locale-message-formatter

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