diff --git a/src/frontend/src/components/plugins/RemoteComponent.tsx b/src/frontend/src/components/plugins/RemoteComponent.tsx index 5d5157bef2..71a586ed87 100644 --- a/src/frontend/src/components/plugins/RemoteComponent.tsx +++ b/src/frontend/src/components/plugins/RemoteComponent.tsx @@ -32,13 +32,13 @@ export default function RemoteComponent({ context: InvenTreePluginContext; }>) { const componentRef = useRef(); - const [rootElement, setRootElement] = useState(null); + const rootElement = useRef(null); useEffect(() => { - if (componentRef.current && !rootElement) { - setRootElement(createRoot(componentRef.current)); + if (componentRef.current && rootElement.current === null) { + rootElement.current = createRoot(componentRef.current); } - }, [componentRef.current]); + }, [rootElement]); const [renderingError, setRenderingError] = useState( undefined @@ -58,7 +58,7 @@ export default function RemoteComponent({ }, [source, defaultFunctionName]); const reloadPluginContent = useCallback(() => { - if (!rootElement) { + if (!rootElement.current) { return; } @@ -80,7 +80,7 @@ export default function RemoteComponent({ // Render the plugin component into the target element // Note that we have to provide the right context(s) to the component // This approach ensures that the component is rendered in the correct context tree - rootElement.render( + rootElement.current?.render( { reloadPluginContent(); - }, [source, func, context, rootElement]); + }, [func, context, rootElement.current]); return (