From 440c71d9fba632c577d4fc724537fed062152900 Mon Sep 17 00:00:00 2001 From: ztplz Date: Mon, 16 Sep 2019 18:19:18 +0800 Subject: [PATCH] Improve code for better compatibility --- components/_util/responsiveObserve.ts | 4 +++- components/carousel/index.tsx | 4 +++- components/layout/Sider.tsx | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/components/_util/responsiveObserve.ts b/components/_util/responsiveObserve.ts index 3135b0304f46..a977331022f1 100644 --- a/components/_util/responsiveObserve.ts +++ b/components/_util/responsiveObserve.ts @@ -2,6 +2,7 @@ // https://github.com/WickyNilliams/enquire.js/issues/82 let enquire: any; +// TODO: Will be removed in antd 4.0 because we will no longer support ie9 if (typeof window !== 'undefined') { const matchMediaPolyfill = (mediaQuery: string) => { return { @@ -11,7 +12,8 @@ if (typeof window !== 'undefined') { removeListener() {}, }; }; - window.matchMedia = window.matchMedia || matchMediaPolyfill; + // ref: https://github.com/ant-design/ant-design/issues/18774 + if (!window.matchMedia) window.matchMedia = matchMediaPolyfill as any; // eslint-disable-next-line global-require enquire = require('enquire.js'); } diff --git a/components/carousel/index.tsx b/components/carousel/index.tsx index ed3e0f7a6465..24cfeae13dbf 100644 --- a/components/carousel/index.tsx +++ b/components/carousel/index.tsx @@ -6,6 +6,7 @@ import warning from '../_util/warning'; // matchMedia polyfill for // https://github.com/WickyNilliams/enquire.js/issues/82 +// TODO: Will be removed in antd 4.0 because we will no longer support ie9 if (typeof window !== 'undefined') { const matchMediaPolyfill = (mediaQuery: string) => { return { @@ -15,7 +16,8 @@ if (typeof window !== 'undefined') { removeListener() {}, }; }; - window.matchMedia = window.matchMedia || matchMediaPolyfill; + // ref: https://github.com/ant-design/ant-design/issues/18774 + if (!window.matchMedia) window.matchMedia = matchMediaPolyfill as any; } // Use require over import (will be lifted up) // make sure matchMedia polyfill run before require('react-slick') diff --git a/components/layout/Sider.tsx b/components/layout/Sider.tsx index 1f6c7bb8d066..540049da3694 100644 --- a/components/layout/Sider.tsx +++ b/components/layout/Sider.tsx @@ -11,6 +11,7 @@ import isNumeric from '../_util/isNumeric'; // matchMedia polyfill for // https://github.com/WickyNilliams/enquire.js/issues/82 +// TODO: Will be removed in antd 4.0 because we will no longer support ie9 if (typeof window !== 'undefined') { const matchMediaPolyfill = (mediaQuery: string) => { return { @@ -20,7 +21,8 @@ if (typeof window !== 'undefined') { removeListener() {}, }; }; - window.matchMedia = window.matchMedia || matchMediaPolyfill; + // ref: https://github.com/ant-design/ant-design/issues/18774 + if (!window.matchMedia) window.matchMedia = matchMediaPolyfill as any; } const dimensionMaxMap = {