Skip to content

Commit 0cd0b7a

Browse files
authored
Merge 94700d4 into 4db0d84
2 parents 4db0d84 + 94700d4 commit 0cd0b7a

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

packages/semi-ui/notification/index.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ const defaultConfig = {
6060
zIndex: 1010,
6161
};
6262

63+
/* REACT_19_START */
64+
// const notificationQueue: Array<{ notice: NoticeProps; id: string }> = [];
65+
/* REACT_19_END */
66+
6367
class NotificationList extends BaseComponent<NotificationListProps, NotificationListState> {
6468
static contextType = ConfigContext;
6569
static propTypes = {
@@ -133,16 +137,19 @@ class NotificationList extends BaseComponent<NotificationListProps, Notification
133137
// if (!this.root) {
134138
// this.root = createRoot(div);
135139
// }
136-
// this.root.render(React.createElement(NotificationList, { ref: instance => (ref = instance) }));
137-
// // 在 React 19 中,render 是同步的,确保 ref 已赋值后再执行add方法
138-
// if (typeof queueMicrotask === 'function') {
139-
// queueMicrotask(() => {
140-
// ref.add({ ...notice, id });
141-
// });
140+
// this.root.render(React.createElement(NotificationList, {
141+
// ref: instance => {
142+
// ref = instance;
143+
// while (notificationQueue.length && ref && typeof ref.add === 'function') {
144+
// const { notice: queuedNotice, id: queuedId } = notificationQueue.shift();
145+
// ref.add({ ...queuedNotice, id: queuedId });
146+
// }
147+
// }
148+
// }));
149+
// if (ref && typeof ref.add === 'function') {
150+
// ref.add({ ...notice, id });
142151
// } else {
143-
// Promise.resolve().then(() => {
144-
// ref.add({ ...notice, id });
145-
// });
152+
// notificationQueue.push({ notice, id });
146153
// }
147154
/* REACT_19_END */
148155
} else {

packages/semi-ui/toast/index.tsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ const createBaseToast = () => class ToastList extends BaseComponent<ToastListPro
4444
zIndex: 1010,
4545
content: '',
4646
};
47+
48+
/* REACT_19_START */
49+
// static toastQueue: Array<{ opts: ToastReactProps, id: string }> = [];
50+
/* REACT_19_END */
51+
4752
static propTypes = {
4853
content: PropTypes.node,
4954
duration: PropTypes.number,
@@ -146,19 +151,22 @@ const createBaseToast = () => class ToastList extends BaseComponent<ToastListPro
146151
// }
147152
// this.root.render(React.createElement(
148153
// ToastList,
149-
// { ref: instance => (ToastList.ref = instance) }
154+
// { ref: instance => {
155+
// ToastList.ref = instance;
156+
// // New: flush toast queue after ref ready
157+
// while (ToastList.toastQueue.length && ToastList.ref && typeof ToastList.ref.add === 'function') {
158+
// const { opts: queuedOpts, id: queuedId } = ToastList.toastQueue.shift();
159+
// ToastList.ref.add({ ...queuedOpts, id: queuedId });
160+
// ToastList.ref.stack = Boolean(queuedOpts.stack);
161+
// }
162+
// } }
150163
// ));
151164
// // 在 React 19 中,render 是同步的,确保 ref 已赋值后再执行add方法
152-
// if (typeof queueMicrotask === 'function') {
153-
// queueMicrotask(() => {
154-
// ToastList.ref.add({ ...opts, id });
155-
// ToastList.ref.stack = Boolean(opts.stack);
156-
// });
165+
// if (ToastList.ref && typeof ToastList.ref.add === 'function') {
166+
// ToastList.ref.add({ ...opts, id });
167+
// ToastList.ref.stack = Boolean(opts.stack);
157168
// } else {
158-
// Promise.resolve().then(() => {
159-
// ToastList.ref.add({ ...opts, id });
160-
// ToastList.ref.stack = Boolean(opts.stack);
161-
// });
169+
// ToastList.toastQueue.push({ opts, id });
162170
// }
163171
/* REACT_19_END */
164172
} else {
@@ -298,11 +306,11 @@ const createBaseToast = () => class ToastList extends BaseComponent<ToastListPro
298306
[`${cssClasses.PREFIX}-innerWrapper`]: true,
299307
[`${cssClasses.PREFIX}-innerWrapper-hover`]: this.state.mouseInSide
300308
})} ref={this.innerWrapperRef} onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave}>
301-
{list.map((item, index) =>{
302-
const isRemoved = removedItems.find(removedItem=>removedItem.id===item.id) !== undefined;
303-
return <CSSAnimation key={item.id} motion={item.motion} animationState={isRemoved?"leave":"enter"} startClassName={isRemoved?`${cssClasses.PREFIX}-animation-hide`:`${cssClasses.PREFIX}-animation-show`}>
309+
{list.map((item, index) => {
310+
const isRemoved = removedItems.find(removedItem => removedItem.id === item.id) !== undefined;
311+
return <CSSAnimation key={item.id} motion={item.motion} animationState={isRemoved ? "leave" : "enter"} startClassName={isRemoved ? `${cssClasses.PREFIX}-animation-hide` : `${cssClasses.PREFIX}-animation-show`}>
304312
{
305-
({ animationClassName, animationEventsNeedBind, isAnimating })=>{
313+
({ animationClassName, animationEventsNeedBind, isAnimating }) => {
306314
return (isRemoved && !isAnimating) ? null : <Toast {...item} stack={this.stack} stackExpanded={this.state.mouseInSide} positionInList={{ length: list.length, index }} className={cls({
307315
[item.className]: Boolean(item.className),
308316
[animationClassName]: true

0 commit comments

Comments
 (0)