Skip to content
Draft
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
10 changes: 10 additions & 0 deletions apps/docs/app/docs/ReactAPI/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ interface DiffOptions {
// Hide the file header with filename and stats
disableFileHeader: false,

// Rethrow rendering errors instead of catching and displaying them
// in the DOM. Useful for testing or custom error handling.
// (default: false)
disableErrorHandling: false,

// Skip syntax highlighting for lines exceeding this length
tokenizeMaxLineLength: 1000,

Expand Down Expand Up @@ -476,6 +481,11 @@ interface FileOptions {
// Hide the file header with filename
disableFileHeader: false,

// Rethrow rendering errors instead of catching and displaying them
// in the DOM. Useful for testing or custom error handling.
// (default: false)
disableErrorHandling: false,

// Skip syntax highlighting for lines exceeding this length
tokenizeMaxLineLength: 1000,

Expand Down
10 changes: 10 additions & 0 deletions apps/docs/app/docs/VanillaAPI/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ const instance = new FileDiff({
// Hide the file header with filename and stats
disableFileHeader: false,

// Rethrow rendering errors instead of catching and displaying them
// in the DOM. Useful for testing or custom error handling.
// (default: false)
disableErrorHandling: false,

// Skip syntax highlighting for lines exceeding this length
tokenizeMaxLineLength: 1000,

Expand Down Expand Up @@ -331,6 +336,11 @@ const instance = new File({
// Hide the file header with filename
disableFileHeader: false,

// Rethrow rendering errors instead of catching and displaying them
// in the DOM. Useful for testing or custom error handling.
// (default: false)
disableErrorHandling: false,

// Skip syntax highlighting for lines exceeding this length
tokenizeMaxLineLength: 1000,

Expand Down
10 changes: 8 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"clsx": "2.1.1",
"cmdk": "1.1.1",
"concurrently": "9.2.1",
"diff": "8.0.2",
"diff": "8.0.3",
"eslint": "9.36.0",
"eslint-plugin-react-hooks": "7.0.0",
"fast-deep-equal": "3.1.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/diffs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pierre/diffs",
"version": "1.0.7",
"version": "1.0.10",
"type": "module",
"license": "apache-2.0",
"scripts": {
Expand Down
13 changes: 12 additions & 1 deletion packages/diffs/src/components/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ export interface FileOptions<LAnnotation>
LineSelectionOptions {
disableFileHeader?: boolean;
renderCustomMetadata?: RenderFileMetadata;
/**
* When true, errors during rendering are rethrown instead of being caught
* and displayed in the DOM. Useful for testing or when you want to handle
* errors yourself.
*/
disableErrorHandling?: boolean;
renderAnnotation?(
annotation: LineAnnotation<LAnnotation>
): HTMLElement | undefined;
Expand Down Expand Up @@ -280,7 +286,8 @@ export class File<LAnnotation = undefined> {
}
this.fileRenderer.setLineAnnotations(this.lineAnnotations);

const { disableFileHeader = false } = this.options;
const { disableFileHeader = false, disableErrorHandling = false } =
this.options;
if (disableFileHeader) {
// Remove existing header from DOM
if (this.headerElement != null) {
Expand Down Expand Up @@ -310,6 +317,10 @@ export class File<LAnnotation = undefined> {
this.renderAnnotations();
this.renderHoverUtility();
} catch (error: unknown) {
if (disableErrorHandling) {
throw error;
}
console.error(error);
if (error instanceof Error) {
this.applyErrorToDOM(error, fileContainer);
}
Expand Down
13 changes: 12 additions & 1 deletion packages/diffs/src/components/FileDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export interface FileDiffOptions<LAnnotation>
) => HTMLElement | DocumentFragment);
disableFileHeader?: boolean;
renderHeaderMetadata?: RenderHeaderMetadataCallback;
/**
* When true, errors during rendering are rethrown instead of being caught
* and displayed in the DOM. Useful for testing or when you want to handle
* errors yourself.
*/
disableErrorHandling?: boolean;
renderAnnotation?(
annotation: DiffLineAnnotation<LAnnotation>
): HTMLElement | undefined;
Expand Down Expand Up @@ -404,7 +410,8 @@ export class FileDiff<LAnnotation = undefined> {

this.hunksRenderer.setLineAnnotations(this.lineAnnotations);

const { disableFileHeader = false } = this.options;
const { disableFileHeader = false, disableErrorHandling = false } =
this.options;

if (disableFileHeader) {
// Remove existing header from DOM
Expand Down Expand Up @@ -436,6 +443,10 @@ export class FileDiff<LAnnotation = undefined> {
this.renderAnnotations();
this.renderHoverUtility();
} catch (error: unknown) {
if (disableErrorHandling) {
throw error;
}
console.error(error);
if (error instanceof Error) {
this.applyErrorToDOM(error, fileContainer);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/diffs/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@
}
}

[data-expand-up] [data-icon] {
[data-expand-down] [data-icon] {
transform: scaleY(-1);
}

Expand Down