Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import { CSSProperties, useEffect, useRef, useState } from 'react';

import type { DiffResult } from './differ';
import calculatePlaceholderHeight from './utils/calculate-placeholder-height';
Expand Down Expand Up @@ -97,7 +97,7 @@ export interface ViewerProps {
/** Extra class names */
className?: string;
/** Extra styles */
style?: React.CSSProperties;
style?: CSSProperties;
}

const DEFAULT_INDENT = 2;
Expand Down Expand Up @@ -127,13 +127,13 @@ const Viewer: React.FC<ViewerProps> = props => {
// Use these refs to keep the diff data and segments sync,
// or it may cause runtime error because of their mismatch.
// Do not use the states to render, use the refs to render and use `updateViewer` to update.
const linesLeftRef = React.useRef(linesLeft);
const linesRightRef = React.useRef(linesRight);
const segmentsRef = React.useRef(getSegments(linesLeft, linesRight, hideUnchangedLines));
const accTopRef = React.useRef<number[]>([]);
const totalHeightRef = React.useRef(0);
const tbodyRef = React.useRef<HTMLTableSectionElement>(null);
const [, forceUpdate] = React.useState({});
const linesLeftRef = useRef(linesLeft);
const linesRightRef = useRef(linesRight);
const segmentsRef = useRef(getSegments(linesLeft, linesRight, hideUnchangedLines));
const accTopRef = useRef<number[]>([]);
const totalHeightRef = useRef(0);
const tbodyRef = useRef<HTMLTableSectionElement>(null);
const [, forceUpdate] = useState({});

const updateViewer = () => {
accTopRef.current = [];
Expand All @@ -158,14 +158,14 @@ const Viewer: React.FC<ViewerProps> = props => {
forceUpdate({});
}

React.useEffect(() => {
useEffect(() => {
linesLeftRef.current = linesLeft;
linesRightRef.current = linesRight;
segmentsRef.current = getSegments(linesLeft, linesRight, hideUnchangedLines);
updateViewer();
}, [hideUnchangedLines, linesLeft, linesRight]);

React.useEffect(() => {
useEffect(() => {
if (!props.virtual || !scrollContainer) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"declaration": true,
"emitDeclarationOnly": true,
"esModuleInterop": true,
"jsx": "react",
"jsx": "react-jsx",
"moduleResolution": "node",
"outDir": "typings",
"resolveJsonModule": true,
Expand Down