Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

LoadingTimeout is missing cleanup function #245

Open
neuhaus-j opened this issue Apr 25, 2024 · 0 comments
Open

LoadingTimeout is missing cleanup function #245

neuhaus-j opened this issue Apr 25, 2024 · 0 comments

Comments

@neuhaus-j
Copy link

Hi @cyntler ,

we are using v1.7.0 to preview Images selected in an Input.

While developing we experienced the following Console Warning:

console.js:273 Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function. in LoadingTimeout (created by Contents) in Contents (created by ProxyRenderer)

So we dug a bit into the readme, tried to set the showLoadingTimeout to false, yet, the warning continued to show up.

Like the warning suggested, we then worked on a cleanup function. Which would change the useEffect of the LoadingTimeout component to look like this:

useEffect(() => {
        if (shouldLoadingRender) {
            return () => {};
        }

        const timer = setTimeout(
            () => {
                setShouldLoadingRender(true);
            },
            typeof config?.loadingRenderer?.showLoadingTimeout === "number"
                ? config.loadingRenderer.showLoadingTimeout
                : 500,
        );

        return () => {
            clearTimeout(timer);
        }
    }, [config?.loadingRenderer?.showLoadingTimeout]);

Notice the early exit if showLoadingTimeout is false.
We think this might be relevant for every version, so i createe this issue.

Let us know, what you think.

Regards,
Jakob

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant