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(sheets-hyper-link-ui): popup observable error on react16 (#2755)

zhangwf0edc5b0f2a1
diff --git a/packages/sheets-hyper-link-ui/src/services/popup.service.ts b/packages/sheets-hyper-link-ui/src/services/popup.service.ts
index 37dfa1b383..e814cd0094 100644
--- a/packages/sheets-hyper-link-ui/src/services/popup.service.ts
+++ b/packages/sheets-hyper-link-ui/src/services/popup.service.ts
@@ -23,7 +23,7 @@ import { BehaviorSubject, Subject } from 'rxjs';
import { Disposable } from '@univerjs/core';
import { CellLinkPopup } from '../views/CellLinkPopup';
-interface IHyperLinkPopup {
+export interface IHyperLinkPopup {
unitId: string;
subUnitId: string;
id: string;
diff --git a/packages/sheets-hyper-link-ui/src/views/CellLinkPopup/index.tsx b/packages/sheets-hyper-link-ui/src/views/CellLinkPopup/index.tsx
index f833d1885c..3cc53694c5 100644
--- a/packages/sheets-hyper-link-ui/src/views/CellLinkPopup/index.tsx
+++ b/packages/sheets-hyper-link-ui/src/views/CellLinkPopup/index.tsx
@@ -16,12 +16,13 @@
import { useDependency } from '@wendellhu/redi/react-bindings';
import { CancelHyperLinkCommand, HyperLinkModel } from '@univerjs/sheets-hyper-link';
-import React from 'react';
+import React, { useEffect, useState } from 'react';
import { AllBorderSingle, CopySingle, LinkSingle, UnlinkSingle, WriteSingle, Xlsx } from '@univerjs/icons';
import { ICommandService, LocaleService } from '@univerjs/core';
import cs from 'clsx';
import { MessageType, Tooltip } from '@univerjs/design';
-import { IMessageService, useObservable } from '@univerjs/ui';
+import { IMessageService } from '@univerjs/ui';
+import type { IHyperLinkPopup } from '../../services/popup.service';
import { SheetsHyperLinkPopupService } from '../../services/popup.service';
import { SheetsHyperLinkResolverService } from '../../services/resolver.service';
import { OpenHyperLinkSidebarOperation } from '../../commands/operations/sidebar.operations';
@@ -43,8 +44,19 @@ export const CellLinkPopup = () => {
const commandService = useDependency(ICommandService);
const messageService = useDependency(IMessageService);
const localeService = useDependency(LocaleService);
- const currentPopup = useObservable(popupService.currentPopup$, popupService.currentPopup);
+ const [currentPopup, setCurrentPopup] = useState<IHyperLinkPopup | null>(null);
const resolverService = useDependency(SheetsHyperLinkResolverService);
+
+ useEffect(() => {
+ setCurrentPopup(popupService.currentPopup);
+ const ob = popupService.currentPopup$.subscribe((popup) => {
+ setCurrentPopup(popup);
+ });
+ return () => {
+ ob.unsubscribe();
+ };
+ }, [popupService.currentPopup, popupService.currentPopup$]);
+
if (!currentPopup) {
return null;
}