Skip to content

Commit

Permalink
feat: 开发模式下相同的错误信息仅报一次
Browse files Browse the repository at this point in the history
  • Loading branch information
saint3347 committed Dec 12, 2024
1 parent 95d5356 commit 5125253
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 19 additions & 7 deletions packages/hooks/src/utils/warning.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
const shownMessages = new Set<string>();

const shouldShowMessage = (message: string) => {
if (shownMessages.has(message)) {
return false;
}
shownMessages.add(message);
return true;
};

const deprecated = (
prop: string,
newProp: string,
component: string,
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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const columns: TableColumnItem[] = [
render: (d) => (
<div id={`name_${d.id}`} style={{ height: d.height }}>
{`${d.firstName} ${d.lastName}`}

<Button text>test</Button>
</div>
),
width: 160,
Expand Down

0 comments on commit 5125253

Please sign in to comment.