Change ad script injection method + fix effect dependency (#396)

## Issue
Tom seeing crashes on the line that was trying to remove the script, saying it's not a child of that node.

## Changes
- I'm guessing the found `fjs` sometimes is not in `head`, but we always remove from `head` during cleanup. Just append to the bottom of head, and remove from head. I think script order doesn't matter if we are injecting at runtime?

- Fixed effect dependency while at it (the latest PR removed the need to check for `type`).
This commit is contained in:
infinite-persistence 2021-11-30 19:17:28 -08:00 committed by GitHub
parent 0aff130ea4
commit 6fb2e02e3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -59,11 +59,10 @@ function Ads(props: Props) {
if (SHOW_ADS) { if (SHOW_ADS) {
let script; let script;
try { try {
let fjs = document.getElementsByTagName('script')[0];
script = document.createElement('script'); script = document.createElement('script');
script.src = scriptUrlToUse; script.src = scriptUrlToUse;
// $FlowFixMe // $FlowFixMe
fjs.parentNode.insertBefore(script, fjs); document.head.appendChild(script);
return () => { return () => {
// $FlowFixMe // $FlowFixMe
@ -73,7 +72,7 @@ function Ads(props: Props) {
} }
// TODO: remove the script when it exists? // TODO: remove the script when it exists?
}, [type]); }, []);
// display to say "sign up to not see these" // display to say "sign up to not see these"
const adsSignInDriver = ( const adsSignInDriver = (