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): fix possible race conditions for ComponentContainer

Wenzhao Hu29af7c2abc3d
diff --git a/packages/ui/src/views/components/ComponentContainer.tsx b/packages/ui/src/views/components/ComponentContainer.tsx
index aca6dcbd51..b4018aeca2 100644
--- a/packages/ui/src/views/components/ComponentContainer.tsx
+++ b/packages/ui/src/views/components/ComponentContainer.tsx
@@ -17,7 +17,7 @@
import { useDependency } from '@wendellhu/redi/react-bindings';
import type { ComponentType } from 'react';
import React, { useMemo, useRef } from 'react';
-import { filter, map } from 'rxjs';
+import { filter, map, startWith } from 'rxjs';
import type { Injector } from '@wendellhu/redi';
import { useObservable } from '../../components/hooks/observable';
import { IUIPartsService } from '../../services/parts/parts.service';
@@ -50,7 +50,8 @@ export function useComponentsOfPart(part: string, injector?: Injector) {
const componentPartUpdateCount = useObservable(
() => uiPartsService.componentRegistered$.pipe(
filter((key) => key === part),
- map(() => updateCounterRef.current += 1)
+ map(() => updateCounterRef.current += 1),
+ startWith(updateCounterRef.current += 1) // trigger update when subscribe
),
undefined,
undefined,