Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: Uniformly hide broken images

haitaoo07f9cf1ac551
diff --git a/ui/src/components/ImgViewer/index.css b/ui/src/components/ImgViewer/index.css
index c70399f1..a129c442 100644
--- a/ui/src/components/ImgViewer/index.css
+++ b/ui/src/components/ImgViewer/index.css
@@ -2,6 +2,6 @@
cursor: zoom-out !important;
}
-.img-viewer img:not(a img, img.broken) {
+.img-viewer img:not(a img, img.broken, img.invisible) {
cursor: zoom-in;
}
diff --git a/ui/src/index.tsx b/ui/src/index.tsx
index ba0aed28..71133668 100644
--- a/ui/src/index.tsx
+++ b/ui/src/index.tsx
@@ -10,6 +10,24 @@ const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement,
);
+/**
+ * Uniformly hide broken images
+ */
+document.addEventListener(
+ 'error',
+ (err) => {
+ const { target } = err;
+ if (target === null || !(target instanceof Element)) {
+ return;
+ }
+
+ if (/IMG/.test(target.nodeName)) {
+ target.classList.add('invisible');
+ }
+ },
+ true,
+);
+
root.render(
<React.StrictMode>
<App />