Skip to content

Commit 0a4ae07

Browse files
improve
1 parent 6069a68 commit 0a4ae07

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

packages/react/src/components/DiffView.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ type DiffViewProps_2<T> = Omit<DiffViewProps<T>, "data"> & {
9797
};
9898
};
9999

100-
const InternalDiffView = <T extends unknown>(props: Omit<DiffViewProps<T>, "data" | "registerHighlighter">) => {
100+
const InternalDiffView = <T extends unknown>(
101+
props: Omit<DiffViewProps<T>, "data" | "registerHighlighter"> & { isMounted: boolean }
102+
) => {
101103
const {
102104
diffFile,
103105
className,
@@ -111,12 +113,11 @@ const InternalDiffView = <T extends unknown>(props: Omit<DiffViewProps<T>, "data
111113
extendData,
112114
diffViewAddWidget,
113115
onAddWidgetClick,
116+
isMounted,
114117
} = props;
115118

116119
const diffFileId = useMemo(() => diffFile.getId(), [diffFile]);
117120

118-
const isMounted = useIsMounted();
119-
120121
const wrapperRef = useRef<HTMLDivElement>();
121122

122123
// performance optimization
@@ -291,6 +292,8 @@ const DiffViewWithRef = <T extends unknown>(
291292
diffFileRef.current = diffFile;
292293
}
293294

295+
const isMounted = useIsMounted();
296+
294297
useEffect(() => {
295298
if (_diffFile && diffFile) {
296299
_diffFile._addClonedInstance(diffFile);
@@ -328,6 +331,7 @@ const DiffViewWithRef = <T extends unknown>(
328331
key={diffFile.getId()}
329332
{...restProps}
330333
diffFile={diffFile}
334+
isMounted={isMounted}
331335
diffViewMode={restProps.diffViewMode || DiffModeEnum.SplitGitHub}
332336
diffViewFontSize={restProps.diffViewFontSize || 14}
333337
/>

packages/react/src/components/tools.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createStore, ref } from "reactivity-store";
44
import type { DiffModeEnum, DiffViewProps, SplitSide } from "./DiffView";
55
import type { RefObject } from "react";
66

7-
export const createDiffConfigStore = (props: DiffViewProps<any>, diffFileId: string) => {
7+
export const createDiffConfigStore = (props: DiffViewProps<any> & { isMounted: boolean }, diffFileId: string) => {
88
return createStore(() => {
99
const id = ref(diffFileId);
1010

@@ -14,7 +14,7 @@ export const createDiffConfigStore = (props: DiffViewProps<any>, diffFileId: str
1414

1515
const setMode = (_mode: DiffModeEnum) => (mode.value = _mode);
1616

17-
const mounted = ref(false);
17+
const mounted = ref(props.isMounted);
1818

1919
const setMounted = (_mounted: boolean) => (mounted.value = _mounted);
2020

0 commit comments

Comments
 (0)