Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(notification): fix Notification triggered for the first time in React 18 concurrent mode #2595

Merged
merged 1 commit into from
Nov 8, 2023
Merged
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
36 changes: 20 additions & 16 deletions src/notification/NotificationList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { forwardRef, useImperativeHandle, useState, useEffect } from 'react';
import { flushSync } from 'react-dom';
import { render } from '../_util/react-render';
import useConfig from '../hooks/useConfig';
import {
Expand Down Expand Up @@ -132,20 +133,23 @@ export const fetchListInstance = (
zIndex: number,
): Promise<NotificationListInstance> =>
new Promise((resolve) => {
if (listMap.has(placement)) {
resolve(listMap.get(placement));
} else {
render(
<NotificationList
attach={attach}
placement={placement}
zIndex={Number(zIndex)}
renderCallback={(instance) => {
listMap.set(placement, instance);
resolve(instance);
}}
/>,
attach,
);
}
// Fix the bug of Notification triggered for the first time in React 18 concurrent mode
flushSync(() => {
if (listMap.has(placement)) {
resolve(listMap.get(placement));
} else {
render(
<NotificationList
attach={attach}
placement={placement}
zIndex={Number(zIndex)}
renderCallback={(instance) => {
listMap.set(placement, instance);
resolve(instance);
}}
/>,
attach,
);
}
});
});
Loading