The code below causes a react-dom error:
import React from "react";
const svg = `<svg><line x1=null y1="10" x2="100" y2="200" /></svg>`;
export default function App() {
return <div dangerouslySetInnerHTML={{ __html: svg }} />;
}
Error: attribute x1: Expected length, "null".
How can I handle this error gracefully?
I expected that adding an error boundary would catch the problem, but it made no difference
import React from "react";
const svg = `<svg><line x1=null y1="10" x2="100" y2="200" /></svg>`;
let withErrorBoundary;
try {
withErrorBoundary = <div dangerouslySetInnerHTML={{ __html: svg }} />;
} catch {
<div>oops! content could not be rendered</div>;
}
export default function App() {
return <div dangerouslySetInnerHTML={{ __html: svg }} />;
}
EDIT: Dump of error as requested by @DennisWash