Skip to content

Commit 53103e2

Browse files
committed
fix(ui-alerts,console): correct Alert live-region role warning and fix console log messages
INSTUI-5131
1 parent 7f94400 commit 53103e2

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

packages/console/src/console.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ function logMessage(
5656
message: string,
5757
...args: unknown[]
5858
) {
59-
const isGitHubPullRequestPreview =
60-
typeof process !== 'undefined' &&
61-
process?.env?.GITHUB_PULL_REQUEST_PREVIEW === 'true'
62-
const isNonProdBuild =
63-
typeof process !== 'undefined' && process?.env?.NODE_ENV !== 'production'
59+
let isNonProdBuild = false
60+
let isGitHubPullRequestPreview = false
61+
try {
62+
isNonProdBuild = process?.env?.NODE_ENV !== 'production'
63+
isGitHubPullRequestPreview =
64+
process?.env?.GITHUB_PULL_REQUEST_PREVIEW === 'true'
65+
} catch {
66+
isNonProdBuild = false
67+
isGitHubPullRequestPreview = false
68+
}
6469
if ((isGitHubPullRequestPreview || isNonProdBuild) && !condition) {
6570
if (typeof console[level] === 'function') {
6671
const renderStack = withRenderStack ? getRenderStack() : ''

packages/ui-alerts/src/Alert/v2/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,13 @@ class Alert extends Component<AlertProps, AlertState> {
153153
}
154154

155155
initLiveRegion(liveRegion: Element) {
156+
const expectedRole =
157+
this.props.liveRegionPoliteness === 'assertive' ? 'alert' : 'status'
158+
const currentRole = liveRegion.getAttribute('role')
159+
156160
error(
157-
liveRegion.getAttribute('role') === 'alert',
158-
`[Alert] live region must have role='alert' set on page load in order to announce content`
161+
currentRole === null || currentRole === expectedRole,
162+
`[Alert] live region has role='${currentRole}', which does not match liveRegionPoliteness='${this.props.liveRegionPoliteness}'. Use role='${expectedRole}' or remove the role attribute.`
159163
)
160164

161165
if (liveRegion) {

0 commit comments

Comments
 (0)