Skip to content

Conversation

memoyil
Copy link
Collaborator

@memoyil memoyil commented Aug 31, 2025

Root cause is, bundle and locale not changing at the same time and if locale used as cache key (https://github.com/pancakeswap/pancake-frontend/blob/develop/apps/web/src/config/constants/meta.ts#L113) it will end up calling obsolete translation function which results old results

To reproduce

Go to swap
Change language
See title remains on the old language


PR-Codex overview

This PR introduces a new LRU (Least Recently Used) caching mechanism to optimize language bundle management in a localization context. It enhances the useLocaleBundle hook and LanguageProvider component by implementing caching for improved performance.

Detailed summary

  • Added LRU class and LRUOptions interface in lru.ts for caching.
  • Updated useLocaleBundle to include language in state and use LRU for caching.
  • Modified LanguageProvider to replace Map with LRU for cache management.
  • Improved cache key handling and interpolation logic in LanguageProvider.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

changeset-bot bot commented Aug 31, 2025

⚠️ No Changeset found

Latest commit: a8a931b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Aug 31, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
solana Ready Ready Preview Comment Aug 31, 2025 2:02pm
web Ready Ready Preview Comment Aug 31, 2025 2:02pm
7 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
aptos-web Ignored Ignored Aug 31, 2025 2:02pm
blog Ignored Ignored Aug 31, 2025 2:02pm
bridge Ignored Ignored Aug 31, 2025 2:02pm
games Ignored Ignored Aug 31, 2025 2:02pm
gamification Ignored Ignored Aug 31, 2025 2:02pm
ton Ignored Ignored Aug 31, 2025 2:02pm
uikit Ignored Ignored Aug 31, 2025 2:02pm

@memoyil memoyil changed the title fix: Page meta not change after language switch fix: Page meta (title etc.) not change after language switch Aug 31, 2025
@memoyil memoyil changed the title fix: Page meta (title etc.) not change after language switch fix: Page meta not change after language switch Aug 31, 2025
@pull-request-size pull-request-size bot added size/L and removed size/S labels Aug 31, 2025

export const LanguageContext = createContext<ContextApi | undefined>(undefined)

const cache = new Map<string, string>()
const cache = new LRU<string, string>({ maxSize: 250 })
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed to lru for avoiding memory issues

const cacheKey = `${lang}:${ver}:${key}-${JSON.stringify(data)}`
if (cache.has(cacheKey)) {

const cacheKey = data ? `${lang}:${ver}:${key}-${JSON.stringify(data)}` : undefined
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no need to use cache where there is no data

bundle: Record<string, string>
ver: number
isFetching: boolean
}>({
}>(() => ({
language: lang,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added to state to change language and bundle at the same time, to avoid render mismatchs

@@ -0,0 +1,79 @@
export interface LRUOptions {
Copy link
Collaborator Author

@memoyil memoyil Aug 31, 2025

Choose a reason for hiding this comment

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

copied directly from utils package to not have dep on it

@memoyil memoyil changed the title fix: Page meta not change after language switch fix: Page meta not change after language switch and memory issues on localization Aug 31, 2025
@memoyil memoyil changed the title fix: Page meta not change after language switch and memory issues on localization fix: Page meta not change after language switch and potential memory issues on localization Aug 31, 2025
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.

1 participant