Skip to content

Commit

Permalink
[DevTools] remove script tag immediately (#26233)
Browse files Browse the repository at this point in the history
Fixes #25924 for React DevTools
specifically.

## Summary

If we remove the script after it's loaded, it creates a race condition
with other code. If some other code is searching for the first script
tag or first element of the document, this might broke it.

## How did you test this change?

I've tested in my local build that even if we remove the script tag
immediately, the code is still correctly executed.
  • Loading branch information
mondaychen authored Feb 24, 2023
1 parent a8f971b commit 5641660
Showing 1 changed file with 1 addition and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ function injectScriptSync(src) {
function injectScriptAsync(src) {
const script = document.createElement('script');
script.src = src;
script.onload = function () {
script.remove();
};
nullthrows(document.documentElement).appendChild(script);
nullthrows(script.parentNode).removeChild(script);
}

let lastDetectionResult;
Expand Down

0 comments on commit 5641660

Please sign in to comment.