From 9c989b2f9c408b7d5988dd0ec8756e86ddf2632f Mon Sep 17 00:00:00 2001 From: Kai Vandivier <49666798+KaiVandivier@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:35:38 +0200 Subject: [PATCH] fix: handle alert returned async by parentAlertsAdd [LIBS-695] (#1388) * fix: handle async parentAlertsAdd * chore: fix comment --- services/alerts/src/useAlert.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/alerts/src/useAlert.ts b/services/alerts/src/useAlert.ts index adc84e211..8b8053d25 100644 --- a/services/alerts/src/useAlert.ts +++ b/services/alerts/src/useAlert.ts @@ -19,13 +19,18 @@ export const useAlert = ( typeof options === 'function' ? options(props) : options if (plugin && parentAlertsAdd && !showAlertsInPlugin) { - alertRef.current = parentAlertsAdd( + // Functions passed through post-robot are asynchronous + parentAlertsAdd( { message: resolvedMessage, options: resolvedOptions, }, alertRef - ) + // Conditional chaining gives backwards compatibility + // with cli-app-scripts < 12 + )?.then((newAlert: Alert) => { + alertRef.current = newAlert + }) } else { alertRef.current = add( {