react-diff-viewer-continued 4.1.3 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,7 +15,8 @@
15
15
  "Bash(pnpm run build:*)",
16
16
  "Bash(pnpm exec vitest:*)",
17
17
  "Bash(grep:*)",
18
- "Bash(pnpm run test:*)"
18
+ "Bash(pnpm run test:*)",
19
+ "Bash(npm run *)"
19
20
  ],
20
21
  "deny": [],
21
22
  "ask": []
@@ -31,8 +31,8 @@ jobs:
31
31
  - name: Install dependencies
32
32
  run: pnpm i
33
33
 
34
- - name: Build worker bundle
35
- run: pnpm run build:worker
34
+ - name: Build
35
+ run: pnpm run build
36
36
 
37
37
  - name: Run unit tests
38
38
  run: pnpm run test
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.2.2 (2026-04-23)
4
+
5
+ ### Bug Fixes
6
+
7
+ - strict typescript types, and visible loader
8
+
9
+ ## 4.2.1 (2026-04-23)
10
+
11
+ ### Bug Fixes
12
+
13
+ - make overscan configurable
14
+ - handle ' HTML entity in diff view to prevent "undefined" suffix
15
+ - mousedown and mouseup
16
+ - do not show content while scrolling fast outside the overscan area
17
+ - update dependencies
18
+ - clean up old package-lock.json
19
+
20
+ ## 4.2.0 (2026-03-10)
21
+
22
+ ### Features
23
+
24
+ - export computeStyles and add missing style override properties
25
+
26
+ ### Bug Fixes
27
+
28
+ - add .js extensions to relative imports for Node.js ESM compatibility
29
+
3
30
  ## 4.1.3 (2026-02-07)
4
31
 
5
32
  ### Bug Fixes
@@ -1,4 +1,4 @@
1
- import { type LineInformation } from "./compute-lines";
1
+ import { type LineInformation } from "./compute-lines.js";
2
2
  export interface Block {
3
3
  index: number;
4
4
  startLine: number;
@@ -23,8 +23,8 @@ export interface DiffInformation {
23
23
  rawValue?: string;
24
24
  }
25
25
  export interface LineInformation {
26
- left?: DiffInformation;
27
- right?: DiffInformation;
26
+ left: DiffInformation;
27
+ right: DiffInformation;
28
28
  }
29
29
  export interface ComputedLineInformation {
30
30
  lineInformation: LineInformation[];
@@ -37,7 +37,7 @@ export interface ComputedDiffInformation {
37
37
  export interface JsDiffChangeObject {
38
38
  added?: boolean;
39
39
  removed?: boolean;
40
- value?: string;
40
+ value: string;
41
41
  }
42
42
  /**
43
43
  * Computes word diff information in the line.
@@ -64,5 +64,5 @@ declare const computeDiff: (oldValue: string | Record<string, unknown>, newValue
64
64
  * @param showLines lines that are always shown, regardless of diff
65
65
  */
66
66
  declare const computeLineInformation: (oldString: string | Record<string, unknown>, newString: string | Record<string, unknown>, disableWordDiff?: boolean, lineCompareMethod?: DiffMethod | ((oldStr: string, newStr: string) => diff.Change[]), linesOffset?: number, showLines?: string[], deferWordDiff?: boolean) => ComputedLineInformation;
67
- declare const computeLineInformationWorker: (oldString: string | Record<string, unknown>, newString: string | Record<string, unknown>, disableWordDiff?: boolean, lineCompareMethod?: DiffMethod | ((oldStr: string, newStr: string) => diff.Change[]), linesOffset?: number, showLines?: string[], deferWordDiff?: boolean) => Promise<ComputedLineInformation>;
67
+ declare const computeLineInformationWorker: (oldString: string | Record<string, unknown>, newString: string | Record<string, unknown>, disableWordDiff?: boolean, lineCompareMethod?: DiffMethod | ((oldStr: string, newStr: string) => diff.Change[]), linesOffset?: number, showLines?: string[], deferWordDiff?: boolean, disableWorker?: boolean) => Promise<ComputedLineInformation>;
68
68
  export { computeLineInformation, computeLineInformationWorker, computeDiff };
@@ -305,24 +305,17 @@ const computeDiff = (oldValue, newValue, compareMethod = DiffMethod.CHARS) => {
305
305
  right: [],
306
306
  };
307
307
  diffArray.forEach(({ added, removed, value }) => {
308
- const diffInformation = {};
309
308
  if (added) {
310
- diffInformation.type = DiffType.ADDED;
311
- diffInformation.value = value;
312
- computedDiff.right.push(diffInformation);
309
+ computedDiff.right.push({ type: DiffType.ADDED, value });
313
310
  }
314
- if (removed) {
315
- diffInformation.type = DiffType.REMOVED;
316
- diffInformation.value = value;
317
- computedDiff.left.push(diffInformation);
311
+ else if (removed) {
312
+ computedDiff.left.push({ type: DiffType.REMOVED, value });
318
313
  }
319
- if (!removed && !added) {
320
- diffInformation.type = DiffType.DEFAULT;
321
- diffInformation.value = value;
322
- computedDiff.right.push(diffInformation);
323
- computedDiff.left.push(diffInformation);
314
+ else {
315
+ const info = { type: DiffType.DEFAULT, value };
316
+ computedDiff.right.push(info);
317
+ computedDiff.left.push(info);
324
318
  }
325
- return diffInformation;
326
319
  });
327
320
  return computedDiff;
328
321
  };
@@ -477,7 +470,7 @@ const computeLineInformation = (oldString, newString, disableWordDiff = false, l
477
470
  }
478
471
  return { right, left };
479
472
  })
480
- .filter(Boolean);
473
+ .filter((x) => x != null);
481
474
  };
482
475
  diffArray.forEach(({ added, removed, value }, index) => {
483
476
  lineInformation = [
@@ -502,20 +495,21 @@ const computeLineInformation = (oldString, newString, disableWordDiff = false, l
502
495
  * @param showLines lines that are always shown, regardless of diff
503
496
  * @returns Promise<ComputedLineInformation> - Resolves with line-by-line diff data from the worker.
504
497
  */
505
- // Import the bundled worker code (generated by scripts/build-worker.js)
506
- import { WORKER_CODE } from './workerBundle';
507
498
  // Cached Blob URL for the worker - created once and reused
508
499
  let workerBlobUrl = null;
509
500
  let workerAvailable = null;
510
- // Create a Blob URL from the bundled worker code
511
- const getWorkerBlobUrl = () => {
501
+ // Lazily import and create a Blob URL from the bundled worker code
502
+ const getWorkerBlobUrl = async () => {
512
503
  if (workerBlobUrl !== null)
513
504
  return workerBlobUrl;
505
+ if (workerAvailable === false)
506
+ return null;
514
507
  if (typeof Worker === 'undefined' || typeof Blob === 'undefined' || typeof URL === 'undefined') {
515
508
  workerAvailable = false;
516
509
  return null;
517
510
  }
518
511
  try {
512
+ const { WORKER_CODE } = await import('./workerBundle.js');
519
513
  const blob = new Blob([WORKER_CODE], { type: 'application/javascript' });
520
514
  workerBlobUrl = URL.createObjectURL(blob);
521
515
  workerAvailable = true;
@@ -526,9 +520,12 @@ const getWorkerBlobUrl = () => {
526
520
  }
527
521
  return workerBlobUrl;
528
522
  };
529
- const computeLineInformationWorker = (oldString, newString, disableWordDiff = false, lineCompareMethod = DiffMethod.CHARS, linesOffset = 0, showLines = [], deferWordDiff = false) => {
523
+ const computeLineInformationWorker = async (oldString, newString, disableWordDiff = false, lineCompareMethod = DiffMethod.CHARS, linesOffset = 0, showLines = [], deferWordDiff = false, disableWorker = false) => {
530
524
  const fallback = () => computeLineInformation(oldString, newString, disableWordDiff, lineCompareMethod, linesOffset, showLines, deferWordDiff);
531
- const blobUrl = getWorkerBlobUrl();
525
+ if (disableWorker) {
526
+ return Promise.resolve(fallback());
527
+ }
528
+ const blobUrl = await getWorkerBlobUrl();
532
529
  if (!blobUrl) {
533
530
  return Promise.resolve(fallback());
534
531
  }
@@ -538,7 +535,6 @@ const computeLineInformationWorker = (oldString, newString, disableWordDiff = fa
538
535
  worker = new Worker(blobUrl);
539
536
  }
540
537
  catch (_a) {
541
- // Worker instantiation failed - fall back to synchronous computation
542
538
  workerAvailable = false;
543
539
  resolve(fallback());
544
540
  return;
@@ -548,7 +544,6 @@ const computeLineInformationWorker = (oldString, newString, disableWordDiff = fa
548
544
  worker.terminate();
549
545
  };
550
546
  worker.onerror = () => {
551
- // Worker error - fall back and mark as unavailable for future calls
552
547
  workerAvailable = false;
553
548
  worker.terminate();
554
549
  resolve(fallback());
@@ -1,4 +1,4 @@
1
- import { computeLineInformation } from "./compute-lines";
1
+ import { computeLineInformation } from "./compute-lines.js";
2
2
  /**
3
3
  * This sets up a message handler inside the Web Worker.
4
4
  * When the main thread sends a message to this worker (via postMessage), this function is triggered.
@@ -11,6 +11,7 @@ export declare enum LineNumberPrefix {
11
11
  export interface InfiniteLoadingProps {
12
12
  pageSize: number;
13
13
  containerHeight: string;
14
+ overscan?: number;
14
15
  }
15
16
  export interface ComputedDiffResult {
16
17
  lineInformation: LineInformation[];
@@ -39,8 +40,8 @@ export interface ReactDiffViewerProps {
39
40
  type: DiffType;
40
41
  prefix: LineNumberPrefix;
41
42
  value: string | DiffInformation[];
42
- additionalLineNumber: number;
43
- additionalPrefix: LineNumberPrefix;
43
+ additionalLineNumber?: number;
44
+ additionalPrefix?: LineNumberPrefix;
44
45
  styles: ReactDiffViewerStyles;
45
46
  }) => ReactElement;
46
47
  highlightLines?: string[];
@@ -69,17 +70,23 @@ export interface ReactDiffViewerProps {
69
70
  * Show debug overlay with virtualization info (for development)
70
71
  */
71
72
  showDebugInfo?: boolean;
73
+ /**
74
+ * Disable Web Worker for diff computation, using synchronous fallback instead.
75
+ * Useful when the worker bundle fails to load in certain bundler configurations.
76
+ */
77
+ disableWorker?: boolean;
72
78
  }
73
79
  export interface ReactDiffViewerState {
74
- expandedBlocks?: number[];
80
+ expandedBlocks: number[];
75
81
  noSelect?: "left" | "right";
76
- scrollableContainerRef: RefObject<HTMLDivElement>;
82
+ scrollableContainerRef: RefObject<HTMLDivElement | null>;
77
83
  computedDiffResult: Record<string, ComputedDiffResult>;
78
84
  isLoading: boolean;
79
85
  visibleStartRow: number;
80
86
  contentColumnWidth: number | null;
81
87
  charWidth: number | null;
82
88
  cumulativeOffsets: number[] | null;
89
+ isScrolling: boolean;
83
90
  }
84
91
  declare class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiffViewerState> {
85
92
  private styles;
@@ -88,6 +95,8 @@ declare class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiff
88
95
  private charMeasureRef;
89
96
  private stickyHeaderRef;
90
97
  private resizeObserver;
98
+ private scrollDebounceTimer;
99
+ private lastRenderedRange;
91
100
  static defaultProps: ReactDiffViewerProps;
92
101
  constructor(props: ReactDiffViewerProps);
93
102
  /**
@@ -248,4 +257,5 @@ declare class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiff
248
257
  }
249
258
  export default DiffViewer;
250
259
  export { DiffMethod };
251
- export type { ReactDiffViewerStylesOverride };
260
+ export { default as computeStyles } from "./styles.js";
261
+ export type { ReactDiffViewerStylesOverride, ReactDiffViewerStyles };