From 5b07a9fe49f59828a509995772e5923c8bb89526 Mon Sep 17 00:00:00 2001 From: Jindorf Date: Wed, 10 Jan 2024 15:30:56 +0100 Subject: [PATCH] fix(locale): memory leak with default rtl values #18965 (#18975) fixes #18965 Co-authored-by: Indorf, Jannik Co-authored-by: John Leider --- packages/vuetify/src/composables/locale.ts | 49 ++++++++++++++++++- .../src/locale/__tests__/index.spec.ts | 4 +- packages/vuetify/src/locale/index.ts | 44 ----------------- 3 files changed, 49 insertions(+), 48 deletions(-) diff --git a/packages/vuetify/src/composables/locale.ts b/packages/vuetify/src/composables/locale.ts index bcedbfe2ba4..bb06bc701c2 100644 --- a/packages/vuetify/src/composables/locale.ts +++ b/packages/vuetify/src/composables/locale.ts @@ -1,6 +1,5 @@ // Utilities import { computed, inject, provide, ref } from 'vue' -import { defaultRtl } from '@/locale' import { createVuetifyAdapter } from '@/locale/adapters/vuetify' // Types @@ -81,8 +80,54 @@ export interface RtlInstance { export const RtlSymbol: InjectionKey = Symbol.for('vuetify:rtl') +function genDefaults () { + return { + af: false, + ar: true, + bg: false, + ca: false, + ckb: false, + cs: false, + de: false, + el: false, + en: false, + es: false, + et: false, + fa: true, + fi: false, + fr: false, + hr: false, + hu: false, + he: true, + id: false, + it: false, + ja: false, + ko: false, + lv: false, + lt: false, + nl: false, + no: false, + pl: false, + pt: false, + ro: false, + ru: false, + sk: false, + sl: false, + srCyrl: false, + srLatn: false, + sv: false, + th: false, + tr: false, + az: false, + uk: false, + vi: false, + zhHans: false, + zhHant: false, + } +} + export function createRtl (i18n: LocaleInstance, options?: RtlOptions): RtlInstance { - const rtl = ref>(options?.rtl ?? defaultRtl) + const rtl = ref>(options?.rtl ?? genDefaults()) const isRtl = computed(() => rtl.value[i18n.current.value] ?? false) return { diff --git a/packages/vuetify/src/locale/__tests__/index.spec.ts b/packages/vuetify/src/locale/__tests__/index.spec.ts index 9c2635c0e13..d350805a4c9 100755 --- a/packages/vuetify/src/locale/__tests__/index.spec.ts +++ b/packages/vuetify/src/locale/__tests__/index.spec.ts @@ -6,7 +6,7 @@ import * as locales from '../' describe('locales', () => { it('should have listed all available locales in index.ts', async () => { - const imported = Object.keys(locales).filter(key => key !== 'defaultRtl') + const imported = Object.keys(locales).filter(key => key !== 'default') const dir = fs.readdirSync(path.resolve(__dirname, '..')) .filter(filename => !['adapters', 'index.ts', '__tests__'].includes(filename)) .map(filename => filename.replace(/\.ts$/, '').replace('-', '')) @@ -22,6 +22,6 @@ describe('locales', () => { }, {} as Record) const enUnfilled = unfill(locales.en) - Object.entries(locales).forEach(([locale, messages]) => locale !== 'defaultRtl' && expect(unfill(messages)).toStrictEqual(enUnfilled)) + Object.entries(locales).forEach(([locale, messages]) => locale !== 'default' && expect(unfill(messages)).toStrictEqual(enUnfilled)) }) }) diff --git a/packages/vuetify/src/locale/index.ts b/packages/vuetify/src/locale/index.ts index 9669aeb6179..14291b29252 100755 --- a/packages/vuetify/src/locale/index.ts +++ b/packages/vuetify/src/locale/index.ts @@ -40,47 +40,3 @@ export { default as uk } from './uk' export { default as vi } from './vi' export { default as zhHans } from './zh-Hans' export { default as zhHant } from './zh-Hant' - -export const defaultRtl = { - af: false, - ar: true, - bg: false, - ca: false, - ckb: false, - cs: false, - de: false, - el: false, - en: false, - es: false, - et: false, - fa: true, - fi: false, - fr: false, - hr: false, - hu: false, - he: true, - id: false, - it: false, - ja: false, - ko: false, - lv: false, - lt: false, - nl: false, - no: false, - pl: false, - pt: false, - ro: false, - ru: false, - sk: false, - sl: false, - srCyrl: false, - srLatn: false, - sv: false, - th: false, - tr: false, - az: false, - uk: false, - vi: false, - zhHans: false, - zhHant: false, -}