[Bug]: Toaster throws in development when it has a style prop
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- react, typescript
- Ambito
- frontend
Direzione di ricerca
Trova useToaster_unstable e useToasterStyles_unstable nel pacchetto react-toast di questo monorepo. useToaster_unstable passa gli stessi rootProps (e quindi lo style del chiamante) a tutti e sei gli slot di posizione, e useToasterStyles_unstable scrive in state.<slot>.style con Object.assign. Inizia eseguendo il repro.cjs del gist contro una build locale per vedere il throw e gli stili di posizione condivisi. Fatto significa che ogni slot riceve un nuovo oggetto che porta i propri stili di posizione, e il repro stampa valori bottom-start e bottom-end distinti senza lanciare un throw.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 20.4k
- Fork
- 3k
- Merge medio
- 3g 15h
- PR unite (30g)
- 74
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/fluentui
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 2 giorni
-
[Bug]: AriaLiveAnnouncer holds back a message announced in the commit that mounts itForse già presa @dmytrokirpa l’ha presa 2 giorni fa. ApertaArea: Accessibility Fluent UI react-components (v9) Type: Bug :bug:
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
microsoft/fluentui#37202 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 2 giorni
-
[Bug]: MessageBar announces the title and body without a space between themForse già presa @jakesalvesen l’ha presa 2 giorni fa. ApertaFluent UI react-components (v9) Type: Bug :bug:
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 2 giorni
-
[Bug]: fluent-radio-group ignores value changes while disabledForse già presa @chrisdholt l’ha presa 1 giorno fa. ApertaFluent UI WC (v3) web-components
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
microsoft/fluentui#37198 · 1 assegnatario ·
I maintainer di solito rispondono entro 2 giorni
-
[Bug]: Accordion crashes for scalar `defaultOpenItems={0}` (headless and styled v9)Forse già presa @arniebradfo l’ha presa 22 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di microsoft/fluentui
Issue simili
-
generate_image reference URL guard lets through IPv4-mapped IPv6 hosts and 100.64.0.0/10Forse già presa @goranai l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Inbox permission: an allow sent with `updatedInput` is ignored by Claude Code on its own safety checksForse già presa @Raj1v l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
backnotprop/plannotator#4046 ·
I maintainer di solito rispondono entro 1 giorno
-
進捗部屋の管理画面で削除対象を月ごとに絞り込むAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
traPtitech/knoQ_R-UI#290 ·
I maintainer di solito rispondono entro 24 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
farion1231/cc-switch#9981 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
account bug course exam iris lecture
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno