Skip to content

Commit

Permalink
Don't throw in render, just log the error
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Moroz committed Jun 4, 2024
1 parent a5a3075 commit b02edfc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/react/progress/src/Progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ const Progress = React.forwardRef<ProgressElement, ProgressProps>(
} = props;

if ((maxProp || maxProp === 0) && !isValidMaxNumber(maxProp)) {
throw new Error(getInvalidMaxError(`${maxProp}`, 'Progress'));
console.error(getInvalidMaxError(`${maxProp}`, 'Progress'));
}

const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;

if (valueProp !== null && !isValidValueNumber(valueProp, max)) {
throw new Error(getInvalidValueError(`${valueProp}`, 'Progress'));
console.error(getInvalidValueError(`${valueProp}`, 'Progress'));
}

const value = isValidValueNumber(valueProp, max) ? valueProp : null;
Expand Down
11 changes: 7 additions & 4 deletions packages/react/toast/src/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ const ToastProvider: React.FC<ToastProviderProps> = (props: ScopedProps<ToastPro
const isClosePausedRef = React.useRef(false);

if (!label.trim()) {
const error = `Invalid prop \`label\` supplied to \`${PROVIDER_NAME}\`. Expected non-empty \`string\`.`;
throw new Error(error);
console.error(
`Invalid prop \`label\` supplied to \`${PROVIDER_NAME}\`. Expected non-empty \`string\`.`
);
}

return (
Expand Down Expand Up @@ -760,8 +761,10 @@ const ToastAction = React.forwardRef<ToastActionElement, ToastActionProps>(
const { altText, ...actionProps } = props;

if (!altText.trim()) {
const error = `Invalid prop \`altText\` supplied to \`${ACTION_NAME}\`. Expected non-empty \`string\`.`;
throw new Error(error);
console.error(
`Invalid prop \`altText\` supplied to \`${ACTION_NAME}\`. Expected non-empty \`string\`.`
);
return null;
}

return (
Expand Down

0 comments on commit b02edfc

Please sign in to comment.