[Bug]: Toaster throws in development when it has a style prop
Maintainer thường phản hồi trong vòng 2 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- react, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Tìm useToaster_unstable và useToasterStyles_unstable trong gói react-toast của monorepo này. useToaster_unstable truyền cùng các rootProps (và do đó là style của bên gọi) cho cả sáu slot vị trí, và useToasterStyles_unstable ghi vào state.<slot>.style bằng Object.assign. Bắt đầu bằng cách chạy repro.cjs của gist với một bản build cục bộ để thấy throw và các kiểu vị trí dùng chung. Hoàn tất nghĩa là mỗi slot nhận một đối tượng mới mang các kiểu vị trí riêng của nó, và repro in ra các giá trị bottom-start và bottom-end khác nhau mà không ném throw.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 20.4k
- Fork
- 3k
- Merge trung bình
- 3 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 74
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/fluentui
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug]: AriaLiveAnnouncer holds back a message announced in the commit that mounts itCó thể đã có người làm @dmytrokirpa đã nhận 2 ngày trước. Đang mởArea: Accessibility Fluent UI react-components (v9) Type: Bug :bug:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
microsoft/fluentui#37202 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug]: MessageBar announces the title and body without a space between themCó thể đã có người làm @jakesalvesen đã nhận 2 ngày trước. Đang mởFluent UI react-components (v9) Type: Bug :bug:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug]: fluent-radio-group ignores value changes while disabledCó thể đã có người làm @chrisdholt đã nhận 1 ngày trước. Đang mởFluent UI WC (v3) web-components
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
microsoft/fluentui#37198 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug]: Accordion crashes for scalar `defaultOpenItems={0}` (headless and styled v9)Có thể đã có người làm @arniebradfo đã nhận 22 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của microsoft/fluentui
Issue tương tự
-
generate_image reference URL guard lets through IPv4-mapped IPv6 hosts and 100.64.0.0/10Có thể đã có người làm @goranai đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Inbox permission: an allow sent with `updatedInput` is ignored by Claude Code on its own safety checksCó thể đã có người làm @Raj1v đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
backnotprop/plannotator#4046 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
進捗部屋の管理画面で削除対象を月ごとに絞り込むĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
traPtitech/knoQ_R-UI#290 ·
Maintainer thường phản hồi trong vòng 24 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
farion1231/cc-switch#9981 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
account bug course exam iris lecture
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày