B
B
buddyletsgostudy2021-09-24 12:17:57
JavaScript
buddyletsgostudy, 2021-09-24 12:17:57

How to remove processes started by already deleted script inside SPA in React?

Any help would be greatly appreciated.
To the question:
The situation forced the use of third-party JS code inside React.
I add this code at ComponentDidMount by adding a script tag to the DOM with the specified src.
With ComponentWillUnmount, I remove the added script tag in order to avoid cloning and unnecessary load on other sections of my SPA.
When you move to another section of the application, the tag, as it should, is removed. BUT, the processes that were launched by this third-party code remain. And they start loading the entire application. I see it in debug tools.
If you make several transitions back and forth, then these processes will multiply to such an extent that even the browser itself will begin to freeze.
What am I missing?....
How to remove processes started by already deleted script inside SPA in React?

UPD: I forgot to mention that third-party code is obfuscated. It is not possible to work inside it.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alex, 2021-09-24
@buddyletsgostudy

Well, for good, third-party code should support some kind of api: callbacks or signals or something to stop itself. Especially if there are some heavy operations. If there is none, you can try to break it so that it throws an exception and stops.

A
Alexandroppolus, 2021-09-24
@Alexandroppolus

Remember the fact that this third party code was added and don't add it again. You can just leave the tag.
In general, this code is wrapped in IIFE, and it will not work to get inside it. If it does not check any external flags, does not interact with external variables and functions, then nothing. And if it interacts, then you need to look at the situation, what exactly is there.

P
profesor08, 2021-09-24
@profesor08

If that script performs only some calculations, then try to make a service worker, run that script in it. And through messages, communicate with the service worker and receive data from it already in the react.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question