[Bug]: AriaLiveAnnouncer holds back a message announced in the commit that mounts it

未关闭 适合新手
#37,202 1 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 2 天内回复

@dmytrokirpa 已经在做这个了。

开始于 2026年11月23日。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
85/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
react, typescript

调研方向

从 useDomAnnounce.ts 中创建 live region 元素的 effect 开始,以及 queueMessage 中的提前返回 if (timeoutRef.current || !elementRef.current)。运行现有的 AriaLiveAnnouncer 单元测试,然后添加一个用例:子组件在挂载 announcer 的同一次 commit 中 announce。当该消息在元素存在后即被写入、而不是等待下一次 announce 时,即完成。

由索引模型根据 Issue 内容生成。

描述

Area: Accessibility Fluent UI react-components (v9) Type: Bug :bug:
Component

Utilities

Package version

9.75.2

React version

19.3.1

Environment
System:
    OS: Windows 11 10.0.26200
    CPU: 11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz
    Memory: 15.7 GB
  Binaries:
    Node: 26.13.1
    npm: 12.2.3
  npmPackages:
    @fluentui/react-components: 9.75.2 => 9.75.2
    @fluentui/react-aria: 9.17.16 => 9.17.16
    react: 19.3.1 => 19.3.1
    react-dom: 19.3.1 => 19.3.1
Current Behavior

A message that is announced in the same commit that mounts AriaLiveAnnouncer is not written to the live region. It stays in the queue and is written later, together with the next message, whenever that one comes.

<AriaLiveAnnouncer>
  <MessageBar>
    <MessageBarBody>First message</MessageBarBody>
  </MessageBar>
</AriaLiveAnnouncer>

Nothing is announced when this renders. When a second MessageBar with Second message is added later, the live region gets First message. Second message. . So the first message is announced at the wrong time, joined to an unrelated one, or never if nothing else is announced.

MessageBar announces on mount, so a MessageBar that is part of the first render of an app is the common case. A component that calls useAnnounce().announce() in a mount effect behaves the same way.

The cause, in useDomAnnounce.ts on master:

  • The live region element is created in an effect. The effects of children run before the effects of their parent, so the child calls announce before the element exists.
  • announce puts the message in the queue and calls queueMessage, which returns early at if (timeoutRef.current || !elementRef.current).
  • Nothing calls queueMessage again when the element is created, so the queue waits for the next announce.

This affects the live region path, which is used when document.ariaNotify is not available. That API is recent, so most of the browser versions in the Browser Support Matrix (apps/public-docsite-v9/src/Concepts/BrowserSupportMatrix.mdx: Edge and Chrome from 84, Firefox from 75, Safari from 14.1) use this path. The ariaNotify path passes each message on directly.

Output of the script in the reproduction link:

CASE 1 the first MessageBar renders together with AriaLiveAnnouncer
  first render, with "First message": nothing written to the live region
  1.5 s later, "Second message" is added: "First message. Second message. "
CASE 2 AriaLiveAnnouncer renders first
  first render, no MessageBar: nothing written to the live region
  1.5 s later, "First message" is added: "First message. "
  1.5 s later, "Second message" is added: "Second message. "

I see the same in a browser, with a Cypress component test on master (4f812d44, Electron 130, which has no document.ariaNotify), with and without strict mode.

Expected Behavior

A message that was queued before the live region element existed is written once the element is created, as it is when AriaLiveAnnouncer was mounted earlier.

Starting the queue from the effect that creates the element does that:

elementRef.current = element;

if (messageQueue.peek()) {
  queueMessage();
}

With that change the first message is written on its own in the cases above, and the AriaLiveAnnouncer unit tests still pass.

Reproduction

https://gist.github.com/jakesalvesen/b8be4546f95536f583f5c812c29729bf

Steps to reproduce
  1. In an empty directory run npm i @fluentui/[email protected] react@19 react-dom@19 jsdom.
  2. Save repro.cjs from the gist and run node repro.cjs.
  3. App.jsx shows the first case in a browser. It needs a browser without document.ariaNotify.

The script renders AriaLiveAnnouncer and prints what is written to its live region after each render. jsdom does not implement innerText, which the announcer uses to write the message, so the script maps innerText to textContent.

Are you reporting an Accessibility issue?

yes

Suggested severity

Low - Has or doesn't need a workaround

Products/sites affected

No response

Are you willing to submit a PR to fix?

yes

Validations
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • The provided reproduction is a minimal reproducible example of the bug.
主要语言
TypeScript
星标
20.4k
派生
3k
平均合并
3 天 15 小时
30 天内合并 PR
74

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/fluentui 的其他 Issue

查看 microsoft/fluentui 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。