@draftbase/renderer 0.5.4 → 0.5.5
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Component, type ReactNode } from "react";
|
|
1
|
+
import { Component, type ErrorInfo, type ReactNode } from "react";
|
|
2
2
|
interface MDXErrorBoundaryProps {
|
|
3
3
|
children: ReactNode;
|
|
4
4
|
fallback: ReactNode;
|
|
5
|
-
onError?: (error: unknown) => void;
|
|
5
|
+
onError?: (error: unknown, errorInfo: ErrorInfo) => void;
|
|
6
6
|
}
|
|
7
7
|
interface MDXErrorBoundaryState {
|
|
8
8
|
hasError: boolean;
|
|
@@ -12,7 +12,7 @@ export declare class MDXErrorBoundary extends Component<MDXErrorBoundaryProps, M
|
|
|
12
12
|
static getDerivedStateFromError(): {
|
|
13
13
|
hasError: boolean;
|
|
14
14
|
};
|
|
15
|
-
componentDidCatch(error: unknown): void;
|
|
15
|
+
componentDidCatch(error: unknown, errorInfo: ErrorInfo): void;
|
|
16
16
|
render(): ReactNode;
|
|
17
17
|
}
|
|
18
18
|
export {};
|
package/dist/MDXErrorBoundary.js
CHANGED
|
@@ -7,9 +7,9 @@ export class MDXErrorBoundary extends Component {
|
|
|
7
7
|
static getDerivedStateFromError() {
|
|
8
8
|
return { hasError: true };
|
|
9
9
|
}
|
|
10
|
-
componentDidCatch(error) {
|
|
11
|
-
console.error("MDX content failed to render", error);
|
|
12
|
-
this.props.onError?.(error);
|
|
10
|
+
componentDidCatch(error, errorInfo) {
|
|
11
|
+
console.error("MDX content failed to render", error, errorInfo.componentStack);
|
|
12
|
+
this.props.onError?.(error, errorInfo);
|
|
13
13
|
}
|
|
14
14
|
render() {
|
|
15
15
|
return this.state.hasError ? this.props.fallback : this.props.children;
|
package/dist/reactNative.js
CHANGED
|
@@ -27,7 +27,12 @@ export function createReactNativeRenderer(primitives, styleOptions) {
|
|
|
27
27
|
tree = processor.parse(source);
|
|
28
28
|
}
|
|
29
29
|
catch (error) {
|
|
30
|
-
return {
|
|
30
|
+
return {
|
|
31
|
+
ok: false,
|
|
32
|
+
error: new Error(`MDX parse failed (${source.length} chars): ${describeError(error)}`, {
|
|
33
|
+
cause: error,
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
31
36
|
}
|
|
32
37
|
// Reference-style links/images (`[text][ref]` + a `[ref]: url` definition anywhere in the
|
|
33
38
|
// doc) resolve against whichever `definition` node shares their identifier — collect them
|
|
@@ -76,13 +81,27 @@ function renderNode(node, ctx, key) {
|
|
|
76
81
|
return renderNodeUnsafe(node, ctx, key);
|
|
77
82
|
}
|
|
78
83
|
catch (error) {
|
|
79
|
-
|
|
84
|
+
const label = node.name ? `<${node.name}>` : node.type;
|
|
85
|
+
const wrapped = new Error(`MDX node "${label}" failed to render: ${describeError(error)}`, {
|
|
86
|
+
cause: error,
|
|
87
|
+
});
|
|
88
|
+
console.error(wrapped.message, error);
|
|
80
89
|
const raw = node.position
|
|
81
90
|
? ctx.source.slice(node.position.start.offset, node.position.end.offset)
|
|
82
|
-
: `<${
|
|
83
|
-
|
|
91
|
+
: `<${label}>`;
|
|
92
|
+
try {
|
|
93
|
+
return jsx(ctx.components.p, { children: raw }, key);
|
|
94
|
+
}
|
|
95
|
+
catch (fallbackError) {
|
|
96
|
+
throw new Error(`MDX node "${label}" failed to render and had no fallback component`, {
|
|
97
|
+
cause: fallbackError,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
84
100
|
}
|
|
85
101
|
}
|
|
102
|
+
function describeError(error) {
|
|
103
|
+
return error instanceof Error ? error.message : String(error);
|
|
104
|
+
}
|
|
86
105
|
function renderNodeUnsafe(node, ctx, key) {
|
|
87
106
|
const { components } = ctx;
|
|
88
107
|
switch (node.type) {
|