Skip to content

Commit fabf8da

Browse files
fix merge usage
1 parent c5afec9 commit fabf8da

4 files changed

Lines changed: 40 additions & 7 deletions

File tree

packages/core/src/diff-file.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,10 @@ export class DiffFile {
813813

814814
getBundle = () => {
815815
// common
816+
const hasInitRaw = this.#hasInitRaw;
817+
const hasInitSyntax = this.#hasInitSyntax;
818+
const hasBuildSplit = this.#hasBuildSplit;
819+
const hasBuildUnified = this.#hasBuildUnified;
816820
const oldFileLines = this.#oldFileLines;
817821
const oldFileDiffLines = this.#oldFileDiffLines;
818822
const oldFileSyntaxLines = this.#oldFileSyntaxLines;
@@ -835,6 +839,10 @@ export class DiffFile {
835839
const unifiedLastStartIndex = this.#unifiedLastStartIndex;
836840

837841
return {
842+
hasInitRaw,
843+
hasInitSyntax,
844+
hasBuildSplit,
845+
hasBuildUnified,
838846
oldFileLines,
839847
oldFileDiffLines,
840848
oldFileSyntaxLines,
@@ -856,10 +864,10 @@ export class DiffFile {
856864
};
857865

858866
mergeBundle = (data: ReturnType<DiffFile["getBundle"]>) => {
859-
this.#hasInitRaw = true;
860-
this.#hasInitSyntax = true;
861-
this.#hasBuildSplit = true;
862-
this.#hasBuildUnified = true;
867+
this.#hasInitRaw = data.hasInitRaw;
868+
this.#hasInitSyntax = data.hasInitSyntax;
869+
this.#hasBuildSplit = data.hasBuildSplit;
870+
this.#hasBuildUnified = data.hasBuildUnified;
863871
this.#composeByDiff = data.composeByDiff;
864872

865873
this.#oldFileLines = data.oldFileLines;
@@ -882,4 +890,28 @@ export class DiffFile {
882890

883891
this.notifyAll();
884892
};
893+
894+
_getFullBundle = () => {
895+
const bundle = this.getBundle();
896+
const oldFileResult = this.#oldFileResult;
897+
const newFileResult = this.#newFileResult;
898+
const diffLines = this.#diffLines;
899+
const diffListResults = this.#diffListResults;
900+
901+
return {
902+
...bundle,
903+
oldFileResult,
904+
newFileResult,
905+
diffLines,
906+
diffListResults,
907+
};
908+
};
909+
910+
_mergeFullBundle = (data: ReturnType<DiffFile["_getFullBundle"]>) => {
911+
this.mergeBundle(data);
912+
this.#oldFileResult = data.oldFileResult;
913+
this.#newFileResult = data.newFileResult;
914+
this.#diffLines = data.diffLines;
915+
this.#diffListResults = data.diffListResults;
916+
};
885917
}

packages/react/src/components/DiffView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export const DiffView = <T extends unknown>(props: DiffViewProps<T>) => {
274274
const diffFile = useMemo(() => {
275275
if (_diffFile) {
276276
const diffFile = DiffFile.createInstance({});
277-
diffFile.mergeBundle(_diffFile.getBundle());
277+
diffFile._mergeFullBundle(_diffFile._getFullBundle());
278278
return diffFile;
279279
} else if (data) {
280280
return new DiffFile(

packages/vue/src/components/DiffView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const DiffView = defineComponent<
7070
const getInstance = () => {
7171
if (props.diffFile) {
7272
const diffFile = DiffFile.createInstance({});
73-
diffFile.mergeBundle(props.diffFile.getBundle());
73+
diffFile._mergeFullBundle(props.diffFile._getFullBundle());
7474
return diffFile;
7575
}
7676
if (props.data)

ui/react-example/src/Example.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,10 @@ export function Example() {
200200
delete (reactRoot.current as any)?.__fiber__;
201201
reactApp.current?.render?.(reactElement);
202202
// mount vue
203-
vueApp.current?.unmount?.();
204203
vueApp.current = createApp(vueElement);
205204
vueApp.current.mount(vueRef.current!);
205+
206+
return () => vueApp.current?.unmount?.();
206207
}
207208
}, [diffFileInstance, reactElement]);
208209

0 commit comments

Comments
 (0)