Skip to content

Commit

Permalink
fix(locale): memory leak with default rtl values #18965 (#18975)
Browse files Browse the repository at this point in the history
fixes #18965

Co-authored-by: Indorf, Jannik <jannik.indorf@eventim.de>
Co-authored-by: John Leider <john@vuetifyjs.com>
  • Loading branch information
3 people authored Jan 10, 2024
1 parent 1ff7faa commit 5b07a9f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 48 deletions.
49 changes: 47 additions & 2 deletions packages/vuetify/src/composables/locale.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Utilities
import { computed, inject, provide, ref } from 'vue'
import { defaultRtl } from '@/locale'
import { createVuetifyAdapter } from '@/locale/adapters/vuetify'

// Types
Expand Down Expand Up @@ -81,8 +80,54 @@ export interface RtlInstance {

export const RtlSymbol: InjectionKey<RtlInstance> = 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<Record<string, boolean>>(options?.rtl ?? defaultRtl)
const rtl = ref<Record<string, boolean>>(options?.rtl ?? genDefaults())
const isRtl = computed(() => rtl.value[i18n.current.value] ?? false)

return {
Expand Down
4 changes: 2 additions & 2 deletions packages/vuetify/src/locale/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('-', ''))
Expand All @@ -22,6 +22,6 @@ describe('locales', () => {
}, {} as Record<string, any>)
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))
})
})
44 changes: 0 additions & 44 deletions packages/vuetify/src/locale/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

0 comments on commit 5b07a9f

Please sign in to comment.