Skip to content

Commit

Permalink
fix(pie-toast-provider): DSW-2222 add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
raoufswe committed Jan 3, 2025
1 parent 2d79cd8 commit 8665b27
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/components/pie-toast-provider/src/toaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import { type ExtendedToastProps } from './defs';
*/
export const toaster = {
_getToastProvider (): PieToastProvider | null {
const toastProvider = document.querySelector('pie-toast-provider') as PieToastProvider;
const toastProviders = document.querySelectorAll('pie-toast-provider');

if (!toastProvider) {
if (toastProviders.length === 0) {
console.error('ToastProvider is not initialized.');
return null;
}

return toastProvider;
if (toastProviders.length > 1) {
console.error('Multiple PieToastProviders are found in the DOM. Only one provider is supported currently and should be registered at the root of the app.');
return null;
}

return toastProviders[0];
},
create (toast: ExtendedToastProps) {
const toastProvider = this._getToastProvider();
Expand Down

0 comments on commit 8665b27

Please sign in to comment.