blueberryapps / react-load-script

React component that makes it easy to load 3rd party scripts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Script not load again after react-router changes

jpacora opened this issue · comments

I have a SPA and when I go from the page who use the react-load-script component to other page and then go back to the first page the script dosn't works.

Hi. You mean the script doesn't load again, or it doesn't work at all - like it has never been loaded ?

It shouldn't load the script again when navigation through SPA (but onLoad handler is called again), but the script should work of course.

I'm having the same issue, but I believe this is just the caveat of using react-router.

Once scripts are loaded on a page, I believe they can't be unloaded nor reloaded. Since an SPA stays on the same page, the script in question has to take this into account and work accordingly.

But if you're using a third-party script where you have no source control (like I am) it might not be possible to patch that script so that it works as you'd expect with an SPA ☹️

I'm with bitstrider. The script is never unloaded if a component is unmounted. This causes certain fields to remain even if another user logs into the application.

same problem here

The work around I found was moving import react-load-script from top of your component file into componentDidMount hook. In this way, the script is guaranteed to be reloaded on every re-mount. Hacky though.

but my question is this, since the script tag is loaded on index.html file inside the public folder, and the index.html loads only once, why is it necessary to load the script on a component??