Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(ui): if two messages share the same key, the later should replace the earlier (#4293)

Wenzhao Hudc60cb373cba
diff --git a/packages/design/src/components/message/Message.tsx b/packages/design/src/components/message/Message.tsx
index b719250bef..c42cc6d173 100644
--- a/packages/design/src/components/message/Message.tsx
+++ b/packages/design/src/components/message/Message.tsx
@@ -16,13 +16,13 @@
/* eslint-disable react-refresh/only-export-components */
+import type { CSSProperties, ReactElement } from 'react';
+import type { IDisposable } from '../../type';
import { ErrorSingle, Loading, SuccessSingle, WarningSingle } from '@univerjs/icons';
+import canUseDom from 'rc-util/lib/Dom/canUseDom';
import { render, unmount } from 'rc-util/lib/React/render';
-import type { CSSProperties, ReactElement } from 'react';
import React from 'react';
import { CSSTransition, TransitionGroup } from 'react-transition-group';
-import canUseDom from 'rc-util/lib/Dom/canUseDom';
-import type { IDisposable } from '../../type';
import styles from './index.module.less';
@@ -121,14 +121,19 @@ export class Message implements IDisposable {
}
append(type: MessageType, options: IMessageOptions): IDisposable {
- const { content, duration = 3000 } = options;
- const key = `${Date.now()}`;
-
- this._messages.push({
- key,
- type,
- content,
- });
+ const { content, duration = 3000, key = `${Date.now()}` } = options;
+
+ const existingMessage = this._messages.findIndex((message) => message.key === options.key);
+ if (existingMessage !== -1) {
+ this._messages[existingMessage].content = content;
+ this._messages[existingMessage].type = type;
+ } else {
+ this._messages.push({
+ key,
+ type,
+ content,
+ });
+ }
this.render();