From 512525397310ed38bebe403ae4b423663e4f9245 Mon Sep 17 00:00:00 2001 From: saint3347 Date: Thu, 12 Dec 2024 10:29:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BC=80=E5=8F=91=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E7=9B=B8=E5=90=8C=E7=9A=84=E9=94=99=E8=AF=AF=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=BB=85=E6=8A=A5=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/hooks/src/utils/warning.ts | 26 ++++++++++++++----- .../__example__/07-02-virtual-scroll.tsx | 2 ++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/hooks/src/utils/warning.ts b/packages/hooks/src/utils/warning.ts index 3139be80b..98c5d6e0f 100644 --- a/packages/hooks/src/utils/warning.ts +++ b/packages/hooks/src/utils/warning.ts @@ -1,3 +1,13 @@ +const shownMessages = new Set(); + +const shouldShowMessage = (message: string) => { + if (shownMessages.has(message)) { + return false; + } + shownMessages.add(message); + return true; +}; + const deprecated = ( prop: string, newProp: string, @@ -5,32 +15,34 @@ const deprecated = ( extraMessage?: string ) => { if (process.env.NODE_ENV !== 'production') { - console.error( - `[shineout] '${prop}' in ${component} component is deprecated, please use '${newProp}' instead. ${extraMessage}` - ); + const msg = `[shineout] '${prop}' in ${component} component is deprecated, please use '${newProp}' instead. ${extraMessage}`; + shouldShowMessage(msg) && console.error(msg); } }; const breakingChange = (message: string) => { if (process.env.NODE_ENV !== 'production') { - console.error(`[shineout] ${message}`); + const msg = `[shineout] ${message}`; + shouldShowMessage(msg) && console.error(msg); } }; const devWarn = (message: string) => { if (process.env.NODE_ENV !== 'production') { - console.warn(`[shineout] ${message}`); + shouldShowMessage(message) && console.warn(`[shineout] ${message}`); } }; const conflictWarning = (component: string, prop1: string, prop2: string) => { if (process.env.NODE_ENV !== 'production') { - console.warn(`[shineout] ${prop1} and ${prop2} cannot be used at the same time in ${component}.`); + const msg = `[shineout] ${prop1} and ${prop2} cannot be used at the same time in ${component}.`; + shouldShowMessage(msg) && console.warn(msg); } }; const error = (message: string) => { - console.error(new Error(`[shineout] ${message}`)); + const msg = new Error(`[shineout] ${message}`); + shouldShowMessage(msg.message) && console.error(msg); }; export const devUseWarning = { diff --git a/packages/shineout/src/table/__example__/07-02-virtual-scroll.tsx b/packages/shineout/src/table/__example__/07-02-virtual-scroll.tsx index 87b4c9fb3..6663a0ffe 100644 --- a/packages/shineout/src/table/__example__/07-02-virtual-scroll.tsx +++ b/packages/shineout/src/table/__example__/07-02-virtual-scroll.tsx @@ -34,6 +34,8 @@ const columns: TableColumnItem[] = [ render: (d) => (
{`${d.firstName} ${d.lastName}`} + +
), width: 160,