Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/@adobe/react-spectrum/src/toast/ToastContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ export type CloseFunction = () => void;

function wrapInViewTransition(fn: () => void): void {
if ('startViewTransition' in document) {
document
.startViewTransition(() => {
flushSync(fn);
})
.ready.catch(() => {});
let transition = document.startViewTransition(() => {
flushSync(fn);
});
// Prevents unhandled promise rejections when a transition is
// preempted by another (e.g. overlapping toasts).
transition.finished.catch(() => {});
transition.ready.catch(() => {});
transition.updateCallbackDone.catch(() => {});
} else {
fn();
}
Expand Down
7 changes: 6 additions & 1 deletion starters/docs/src/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ export const queue = new ToastQueue<MyToastContent>({
// Wrap state updates in a CSS view transition.
wrapUpdate(fn) {
if ('startViewTransition' in document) {
document.startViewTransition(() => {
let transition = document.startViewTransition(() => {
flushSync(fn);
});
// Prevents unhandled promise rejections when a transition is
// preempted by another (e.g. overlapping toasts).
transition.finished.catch(() => {});
transition.ready.catch(() => {});
transition.updateCallbackDone.catch(() => {});
} else {
fn();
}
Expand Down
7 changes: 6 additions & 1 deletion starters/tailwind/src/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ export const queue = new ToastQueue<MyToastContent>({
// Wrap state updates in a CSS view transition.
wrapUpdate(fn) {
if ('startViewTransition' in document) {
document.startViewTransition(() => {
let transition = document.startViewTransition(() => {
flushSync(fn);
});
// Prevents unhandled promise rejections when a transition is
// preempted by another (e.g. overlapping toasts).
transition.finished.catch(() => {});
transition.ready.catch(() => {});
transition.updateCallbackDone.catch(() => {});
} else {
fn();
}
Expand Down