Implementing and verifying the integrity of the cleanup function on the core useEffect

This commit is contained in:
Rezmason
2025-05-15 01:36:28 -07:00
parent 22241924c9
commit b7085c5bf7
2 changed files with 31 additions and 17 deletions

View File

@@ -120,16 +120,9 @@ export const Matrix = memo((props) => {
);
};
useEffect(() => {
const useWebGPU = supportsWebGPU() && ["webgpu"].includes(rest.renderer?.toLowerCase());
const isWebGPU = rRenderer?.type === "webgpu";
if (rRenderer != null && useWebGPU === isWebGPU) {
return;
}
const cleanup = () => {
if (rCanvas != null) {
matrix.current.removeChild(rCanvas);
rCanvas.remove();
setCanvas(null);
}
@@ -141,6 +134,17 @@ export const Matrix = memo((props) => {
if (rRenderer != null) {
setRenderer(null);
}
};
useEffect(() => {
const useWebGPU = supportsWebGPU() && ["webgpu"].includes(rest.renderer?.toLowerCase());
const isWebGPU = rRenderer?.type === "webgpu";
if (rRenderer != null && useWebGPU === isWebGPU) {
return;
}
cleanup();
const canvas = document.createElement("canvas");
canvas.style.width = "100%";
@@ -155,6 +159,8 @@ export const Matrix = memo((props) => {
setRain(rain);
};
loadRain();
return cleanup;
}, [props.renderer]);
useEffect(() => {