Skip to content

Commit

Permalink
React: fixed broken SvgImage lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
matafokka committed Apr 18, 2024
1 parent 9d9c175 commit 0bd9b88
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/react-integration/src/SvgImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { onSrcUpdate as onSrcUpdateRaw, onUnmount as onUnmountRaw } from "integr
export interface SvgImageProps extends React.SVGAttributes<SVGElement>, SvgImagePropsRaw {}

export function SvgImage({ src, useElAttrs, ...attrs }: SvgImageProps) {
const [id, setId] = useState("");
let actualId = "";
const [id, setId] = useState(actualId);
const [svgAttrs, setSvgAttrs] = useState<React.SVGAttributes<SVGElement>>({});
let prevSrc = "";

Expand All @@ -14,6 +15,7 @@ export function SvgImage({ src, useElAttrs, ...attrs }: SvgImageProps) {

if (res.id) {
setId(res.id);
actualId = res.id;
}

if (res.attrs) {
Expand All @@ -28,8 +30,8 @@ export function SvgImage({ src, useElAttrs, ...attrs }: SvgImageProps) {

// When component will be unmounted
useEffect(() => {
return () => onUnmountRaw(id);
}, [src]);
return () => onUnmountRaw(actualId);
}, []);

return (
<svg {...{ alt: "", ...attrs, ...svgAttrs }}>
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-awesome-svg-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"vite-awesome-svg-loader",
"svgo"
],
"version": "1.3.4",
"version": "1.3.5",
"homepage": "https://github.com/matafokka/vite-awesome-svg-loader",
"repository": "https://github.com/matafokka/vite-awesome-svg-loader",
"license": "LGPL-2.1-or-later",
Expand Down

0 comments on commit 0bd9b88

Please sign in to comment.