Skip to content

Commit d1566bc

Browse files
update
1 parent ec32cd1 commit d1566bc

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

packages/react/src/components/DiffView.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,19 +299,23 @@ const DiffViewWithRef = <T extends unknown>(
299299
useEffect(() => {
300300
if (!diffFile) return;
301301
diffFile.initTheme(diffViewTheme);
302+
302303
diffFile.initRaw();
304+
303305
diffFile.buildSplitDiffLines();
306+
304307
diffFile.buildUnifiedDiffLines();
305308
}, [diffFile, diffViewTheme]);
306309

307310
useEffect(() => {
308311
if (!diffFile) return;
309-
312+
310313
if (props.diffViewHighlight) {
311314
diffFile.initSyntax({ registerHighlighter });
312-
diffFile.notifyAll();
313315
}
314-
}, [diffFile, props.diffViewHighlight, registerHighlighter]);
316+
317+
diffFile.notifyAll();
318+
}, [diffFile, props.diffViewHighlight, registerHighlighter, diffViewTheme]);
315319

316320
useEffect(() => {
317321
if (!diffFile) return;
@@ -326,7 +330,7 @@ const DiffViewWithRef = <T extends unknown>(
326330
const cb = diffFile.subscribe(init);
327331

328332
return cb;
329-
}, [diffFile, diffViewTheme]);
333+
}, [diffFile]);
330334

331335
// fix react strict mode error
332336
useUnmount(() => (__DEV__ ? diffFile?._destroy?.() : diffFile?.clear?.()), [diffFile]);

packages/solid/src/components/DiffView.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,19 @@ const InternalDiffView = <T extends unknown>(props: DiffViewProps<T>) => {
187187
const initSyntax = () => {
188188
const mounted = isMounted();
189189
const currentDiffFile = diffFile();
190-
if (mounted && currentDiffFile && props.diffViewHighlight) {
191-
currentDiffFile.initSyntax({ registerHighlighter: props.registerHighlighter });
190+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
191+
props.diffViewTheme;
192+
if (mounted && currentDiffFile) {
193+
if (props.diffViewHighlight) {
194+
currentDiffFile.initSyntax({ registerHighlighter: props.registerHighlighter });
195+
}
192196
currentDiffFile.notifyAll();
193197
}
194198
};
195199

196200
const initAttribute = () => {
197201
const mounted = isMounted();
198202
const currentDiffFile = diffFile();
199-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
200-
props.diffViewTheme;
201203
if (mounted && currentDiffFile && wrapperRef()) {
202204
const init = () => {
203205
wrapperRef()?.setAttribute("data-theme", currentDiffFile._getTheme() || "light");

packages/svelte/src/lib/components/DiffView.svelte

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,16 @@
156156
$effect(initDiff);
157157
158158
const initSyntax = () => {
159-
if (!diffFile || !isMounted || !enableHighlight) return;
160-
diffFile.initSyntax({
161-
registerHighlighter: props.registerHighlighter
162-
});
159+
if (!diffFile || !isMounted) return;
160+
161+
theme;
162+
163+
if (enableHighlight) {
164+
diffFile.initSyntax({
165+
registerHighlighter: props.registerHighlighter
166+
});
167+
}
168+
163169
diffFile.notifyAll();
164170
};
165171
@@ -172,8 +178,6 @@
172178
173179
if (!isMounted || !diffFile || !wrapperRef) return;
174180
175-
theme;
176-
177181
const init = () => {
178182
wrapperRef?.setAttribute('data-theme', diffFile._getTheme() || 'light');
179183
wrapperRef?.setAttribute('data-highlighter', diffFile._getHighlighterName());

packages/vue/src/components/DiffView.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,26 @@ export const DiffView = defineComponent<
154154
};
155155

156156
const initSyntax = () => {
157-
if (!isMounted.value || !enableHighlight.value || !diffFile.value) return;
157+
if (!isMounted.value || !diffFile.value) return;
158158

159159
const instance = diffFile.value;
160-
instance.initSyntax({
161-
registerHighlighter: props.registerHighlighter,
162-
});
160+
161+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
162+
theme.value;
163+
164+
if (enableHighlight.value) {
165+
instance.initSyntax({
166+
registerHighlighter: props.registerHighlighter,
167+
});
168+
}
169+
163170
instance.notifyAll();
164171
};
165172

166173
const initAttribute = (onClean: (cb: () => void) => void) => {
167174
if (!isMounted.value || !diffFile.value || !wrapperRef.value) return;
168175
const instance = diffFile.value;
169-
// hack to track the value change
170-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
171-
theme.value;
176+
172177
const init = () => {
173178
wrapperRef.value?.setAttribute("data-theme", instance._getTheme() || "light");
174179
wrapperRef.value?.setAttribute("data-highlighter", instance._getHighlighterName());

0 commit comments

Comments
 (0)