Fix crash caused by freezing Moment.js Locale objects in deepFreeze (#223133)

This commit is contained in:
Steph Milovic 2025-06-09 15:04:08 -06:00 committed by GitHub
parent 5f69154341
commit 855f1c62ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,6 +8,7 @@
*/ */
import type { RecursiveReadonly } from '@kbn/utility-types'; import type { RecursiveReadonly } from '@kbn/utility-types';
import moment from 'moment-timezone';
/** @public */ /** @public */
export type Freezable = { [k: string]: any } | any[]; export type Freezable = { [k: string]: any } | any[];
@ -23,8 +24,16 @@ export function deepFreeze<T extends Freezable>(object: T) {
// recursively frozen as well // recursively frozen as well
for (const value of Object.values(object)) { for (const value of Object.values(object)) {
if (value !== null && typeof value === 'object') { if (value !== null && typeof value === 'object') {
if (isMomentLocale(value)) {
// Skip moment.Locale instances, moment should not be frozen
continue;
}
deepFreeze(value); deepFreeze(value);
} }
} }
return Object.freeze(object) as RecursiveReadonly<T>; return Object.freeze(object) as RecursiveReadonly<T>;
} }
function isMomentLocale(obj: unknown): obj is moment.Locale {
return obj !== null && typeof obj === 'object' && '_longDateFormat' in obj;
}