[Bug]: Toaster throws in development when it has a style prop

Open Beginner friendly
#37,209 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@jakesalvesen is already working on this.

Since Oct 21, 2026.

  • #36962 by @jakesalvesen — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
react, typescript
Domain
frontend

Research direction

Find useToaster_unstable and useToasterStyles_unstable in the react-toast package of this monorepo. useToaster_unstable hands the same rootProps (and so the caller's style) to all six position slots, and useToasterStyles_unstable writes into state.<slot>.style with Object.assign. Start by running the gist's repro.cjs against a local build to see the throw and the shared position styles. Done means each slot gets a new object carrying its own position styles, and the repro prints distinct bottom-start and bottom-end values without throwing.

Written by the indexing model from the issue text.

Description

Component: Toast Fluent UI react-components (v9) Type: Bug :bug:
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_unstable creates the six position slots from the same rootProps, so every slot holds the caller's style object.
  • useToasterStyles_unstable runs state.bottomStart.style ??= {} and Object.assign(state.bottomStart.style, getPositionStyles(...)) for each slot. With a style prop the ??= keeps the caller's object, and Object.assign writes 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
  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 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.
Dominant language
TypeScript
Stars
20.4k
Forks
3k
Avg merge
3d 15h
Merged PRs (30d)
74

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/fluentui

All issues in microsoft/fluentui

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.