@@ -104,18 +104,27 @@ const NotificationContainer = (props: Props) => {
104
104
const componentPath = getContextPath ( )
105
105
106
106
useEffect ( ( ) => {
107
- if ( ! sendNotifications || sendNotifications . length === 0 ) return ;
107
+ // Note - the type checking can be removed when it's handled properly in Dash
108
+ if ( sendNotifications === undefined || sendNotifications === null ) return ;
109
+
110
+ if ( ! Array . isArray ( sendNotifications ) ) {
111
+ throw new Error (
112
+ `Expected 'sendNotifications' to be a list of dictionaries but received: ${ JSON . stringify ( sendNotifications ) } `
113
+ ) ;
114
+ return ;
115
+ }
108
116
109
117
sendNotifications . forEach ( ( notification ) => {
110
118
const { action, ...realNotification } = notification ;
111
119
112
120
// Validate action is one of the accepted values
113
121
if ( ! allowedActions . includes ( action || 'show' ) ) {
114
- console . error ( `Invalid action: '${ action } ' passed to action prop; should be one of '${ allowedActions . join ( "','" ) } '` ) ;
122
+ throw new Error ( `Invalid action: '${ action } ' passed to action prop; should be one of '${ allowedActions . join ( "','" ) } '` ) ;
115
123
return ;
116
124
}
117
125
if ( ! allowedPositions . includes ( realNotification ?. position || 'bottom-right' ) ) {
118
- console . error ( `Invalid position: '${ realNotification ?. position } ' passed to position prop; should be one of '${ allowedPositions . join ( "','" ) } '` ) ;
126
+ throw new Error
127
+ ( `Invalid position: '${ realNotification ?. position } ' passed to position prop; should be one of '${ allowedPositions . join ( "','" ) } '` ) ;
119
128
return ;
120
129
}
121
130
@@ -132,7 +141,14 @@ const NotificationContainer = (props: Props) => {
132
141
} , [ sendNotifications ] ) ;
133
142
134
143
useEffect ( ( ) => {
135
- if ( ! hideNotifications || hideNotifications . length === 0 ) return ;
144
+ if ( hideNotifications === undefined || hideNotifications === null ) return ;
145
+
146
+ if ( ! Array . isArray ( hideNotifications ) ) {
147
+ throw new Error (
148
+ `Expected 'hideNotifications' to be a list of ids but received: ${ JSON . stringify ( hideNotifications ) } `
149
+ ) ;
150
+ return ;
151
+ }
136
152
137
153
hideNotifications . forEach ( ( id ) => {
138
154
notifications . hide ( stringifyId ( id ) ) ;
0 commit comments