[Bug]: Toaster throws in development when it has a style prop
メンテナーはふだん 2 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- react, typescript
- 領域
- frontend
調査の方向性
この monorepo の react-toast パッケージで useToaster_unstable と useToasterStyles_unstable を見つけます。useToaster_unstable は同じ rootProps(つまり呼び出し元の style)を 6 つすべての位置スロットに渡し、useToasterStyles_unstable は state.<slot>.style に Object.assign で書き込みます。まず gist の repro.cjs をローカルビルドに対して実行し、throw と共有された位置スタイルを確認します。完了とは、各スロットが自身の位置スタイルを持つ新しいオブジェクトを受け取り、repro が throw せずに異なる bottom-start と bottom-end の値を出力することです。
索引モデルが issue の本文から書いたものです。
説明
Component
Toast
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-toast: 9.8.5 => 9.8.5
react: 19.3.1 => 19.3.1
react-dom: 19.3.1 => 19.3.1
Current Behavior
A Toaster with a style prop throws in a development build as soon as it renders a second time with a toast.
<Toaster style={{ zIndex: 5 }} />
Dispatch one toast, then dispatch a second one or dismiss the first one:
Cannot assign to read only property 'bottom' of object '#<Object>'
The Toaster writes its position styles into the object that was passed as style. React freezes a style object in development once it has rendered it. The Toaster renders again on its own when a toast is added or dismissed, gets the same object from its props, and the write throws. A new object for every render of the parent does not help, because the parent does not render in between.
The same write also mixes up the positions. With toasts in bottom-start and bottom-end in one render, both containers get the styles of both:
bottom-start: z-index: 5; bottom: 16px; left: 20px; right: 20px;
bottom-end: z-index: 5; bottom: 16px; left: 20px; right: 20px;
So the bottom-end toasts are placed at the left edge, on top of the bottom-start ones.
The cause, on master:
useToaster_unstablecreates the six position slots from the samerootProps, so every slot holds the caller'sstyleobject.useToasterStyles_unstablerunsstate.bottomStart.style ??= {}andObject.assign(state.bottomStart.style, getPositionStyles(...))for each slot. With astyleprop the??=keeps the caller's object, andObject.assignwrites into it.
Without a style prop every slot gets its own new object, so the default Toaster is not affected. Passing the styles through className avoids both problems.
Output of the script in the reproduction link:
CASE 1 one toast, then a second toast
threw: Cannot assign to read only property 'bottom' of object '#<Object>'
CASE 2 one toast, then dismiss it
threw: Cannot assign to read only property 'bottom' of object '#<Object>'
CASE 3 toasts in bottom-start and bottom-end in one render
rendered:
bottom-start: z-index: 5; bottom: 16px; left: 20px; right: 20px;
bottom-end: z-index: 5; bottom: 16px; left: 20px; right: 20px;
I see the same in a browser on master (f4010328), in a Cypress component test with Electron 130 and React 19.2.0. With the style prop, a second toast or a dismissal throws and React unmounts the tree. Without the style prop the same steps work.
Expected Behavior
The Toaster does not write into the object passed as style, and each position container gets its own styles: the caller's styles with the styles of its own position on top.
Building a new object for each slot does that:
state.bottomStart.style = {
...state.bottomStart.style,
...getPositionStyles(TOAST_POSITIONS.bottomStart, state.dir, state.offset),
};
Reproduction
https://gist.github.com/jakesalvesen/412d93debd198e97633503c08f170747
Steps to reproduce
- In an empty directory run
npm i @fluentui/[email protected] react@19 react-dom@19 jsdom. - Save
repro.cjsfrom the gist and runnode repro.cjs. App.jsxshows the same cases in a browser, in a development build.
The script renders <Toaster style={{ zIndex: 5 }} />, dispatches toasts through useToastController and prints the error or the inline styles of the position containers.
Are you reporting an Accessibility issue?
no
Suggested severity
Medium - Has 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時間
- マージ済み PR(30日)
- 74
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/fluentui のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 2 日以内に返信
-
[Bug]: AriaLiveAnnouncer holds back a message announced in the commit that mounts it対応中かも @dmytrokirpa が 2 日前に担当しました。 オープンArea: Accessibility Fluent UI react-components (v9) Type: Bug :bug:
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
microsoft/fluentui#37202 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
[Bug]: MessageBar announces the title and body without a space between them対応中かも @jakesalvesen が 2 日前に担当しました。 オープンFluent UI react-components (v9) Type: Bug :bug:
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 2 日以内に返信
-
[Bug]: fluent-radio-group ignores value changes while disabled対応中かも @chrisdholt が 1 日前に担当しました。 オープンFluent UI WC (v3) web-components
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
microsoft/fluentui#37198 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
[Bug]: Accordion crashes for scalar `defaultOpenItems={0}` (headless and styled v9)対応中かも @arniebradfo が 22 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
microsoft/fluentui の issue をすべて見る
似ている issue
-
generate_image reference URL guard lets through IPv4-mapped IPv6 hosts and 100.64.0.0/10対応中かも @goranai が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
Inbox permission: an allow sent with `updatedInput` is ignored by Claude Code on its own safety checks対応中かも @Raj1v が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
backnotprop/plannotator#4046 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
traPtitech/knoQ_R-UI#290 ·
メンテナーはふだん 24 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
farion1231/cc-switch#9981 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
account bug course exam iris lecture
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信