Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(icons): keep branded svg icons stable across re-renders

damenchofa74383ce7e9
diff --git a/react/features/base/icons/components/SvgXmlIcon.web.tsx b/react/features/base/icons/components/SvgXmlIcon.web.tsx
index 169aa7565f..5162ce1cb7 100644
--- a/react/features/base/icons/components/SvgXmlIcon.web.tsx
+++ b/react/features/base/icons/components/SvgXmlIcon.web.tsx
@@ -8,17 +8,24 @@ import React, { useMemo } from 'react';
const SvgXmlIcon = ({ src, ...rest }: {
src: string;
}): JSX.Element => {
- const svgDocument = new DOMParser().parseFromString(src, 'image/svg+xml');
- const element = svgDocument.documentElement.outerHTML;
- const attributes = useMemo(() => Object.entries(rest).map(
- ([ key, value ]) => `${key}="${value}"`)
- .join(' '), [ rest ]);
+ const attributes = Object.entries(rest)
+ .filter(([ , value ]) => value !== undefined)
+ .map(([ key, value ]) => `${key}="${value}"`)
+ .join(' ');
- const html = element.replace('<svg', `<svg ${attributes}`);
+ // React replaces the inner HTML whenever the dangerouslySetInnerHTML object changes, so keep it
+ // stable while the markup is the same. Otherwise every re-render swaps the svg element and
+ // breaks anything holding a reference to it, like the outside click check of a popover.
+ const markup = useMemo(() => {
+ const svgDocument = new DOMParser().parseFromString(src, 'image/svg+xml');
+ const element = svgDocument.documentElement.outerHTML;
+
+ return { __html: element.replace('<svg', `<svg ${attributes}`) };
+ }, [ src, attributes ]);
return (
<div // eslint-disable-next-line react/no-danger
- dangerouslySetInnerHTML = {{ __html: html }}
+ dangerouslySetInnerHTML = { markup }
{ ...rest } />
);
};