mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 11:05:39 -04:00
Fix crash caused by freezing Moment.js Locale objects in deepFreeze
(#223133)
This commit is contained in:
parent
5f69154341
commit
855f1c62ef
1 changed files with 9 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
|||
*/
|
||||
|
||||
import type { RecursiveReadonly } from '@kbn/utility-types';
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
/** @public */
|
||||
export type Freezable = { [k: string]: any } | any[];
|
||||
|
@ -23,8 +24,16 @@ export function deepFreeze<T extends Freezable>(object: T) {
|
|||
// recursively frozen as well
|
||||
for (const value of Object.values(object)) {
|
||||
if (value !== null && typeof value === 'object') {
|
||||
if (isMomentLocale(value)) {
|
||||
// Skip moment.Locale instances, moment should not be frozen
|
||||
continue;
|
||||
}
|
||||
deepFreeze(value);
|
||||
}
|
||||
}
|
||||
return Object.freeze(object) as RecursiveReadonly<T>;
|
||||
}
|
||||
|
||||
function isMomentLocale(obj: unknown): obj is moment.Locale {
|
||||
return obj !== null && typeof obj === 'object' && '_longDateFormat' in obj;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue