-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2017a6a
commit 97bd37a
Showing
3 changed files
with
217 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
diff --git a/node_modules/react-script-hook/lib/use-script.js b/node_modules/react-script-hook/lib/use-script.js | ||
index b7ba6fc..e66de4b 100644 | ||
--- a/node_modules/react-script-hook/lib/use-script.js | ||
+++ b/node_modules/react-script-hook/lib/use-script.js | ||
@@ -93,6 +93,16 @@ function useScript(_a) { | ||
return function () { | ||
scriptEl.removeEventListener('load', handleLoad); | ||
scriptEl.removeEventListener('error', handleError); | ||
+ | ||
+ // if we unmount, and we are still loading the script, then | ||
+ // remove from the DOM & cache so we have a clean slate next time. | ||
+ // this is similar to the `removeOnUnmount` behavior of the TS useScript hook | ||
+ // https://github.com/juliencrn/usehooks-ts/blob/20667273744a22dd2cd2c48c38cd3c10f254ae47/packages/usehooks-ts/src/useScript/useScript.ts#L134 | ||
+ // but only applied when loading | ||
+ if (status && status.loading) { | ||
+ scriptEl.remove(); | ||
+ delete exports.scripts[src]; | ||
+ } | ||
}; | ||
// we need to ignore the attributes as they're a new object per call, so we'd never skip an effect call | ||
}, [src]); |
Oops, something went wrong.