-
Notifications
You must be signed in to change notification settings - Fork 108
Open
Description
Describe the bug
It appears that when you use the loader
prop an error can happen when loading many SVGs one after the other.
The error points out these lines:
useEffect(() => {
if (status === STATUS.LOADED) {
getElement();
}
}, [status, getElement]);
And the setState here:
const getElement = useCallback(() => {
try {
const node = getNode({ ...props, handleError, hash: hash.current, content }) as Node;
const convertedElement = convert(node);
if (!convertedElement || !isValidElement(convertedElement)) {
throw new Error('Could not convert the src to a React element');
}
setState({
element: convertedElement,
status: STATUS.READY,
});
} catch (error: any) {
handleError(error);
}
}, [content, handleError, props]);
The error is:
hook.js:608 Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.
overrideMethod @ hook.js:608
getRootForUpdatedFiber @ react-dom-client.development.js:3867
enqueueConcurrentHookUpdate @ react-dom-client.development.js:3820
dispatchReducerAction @ react-dom-client.development.js:6914
(anonymous) @ index.tsx:97
(anonymous) @ index.tsx:201
Your minimal, reproducible example
https://codesandbox.io/p/devbox/blissful-turing-hh9rg5?workspaceId=ws_N9re2seS9MZVKPnJDFcBRH
Steps to reproduce
Visit Sandbox linked above, open the console, click the Show Icons button in the Preview, error should appear in the console, may need to wait for more of the icons to load.
Expected behavior
No maximum depth errors when using the loader
prop.
How often does this bug happen?
Often
Screenshots or Videos
No response
Platform
No response
react-inlinesvg version
4.2.0
TypeScript version
5.8.2
Build tool
Vite
Additional context
No response
Metadata
Metadata
Assignees
Labels
No labels