@samitouri / QOS-React-2 / commits / 564166099b

[DevTools] remove script tag immediately (#26233)

Fixes https://github.com/facebook/react/issues/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.

Mengdi Chen committed Feb 24, 2023 at 15:13 UTC 564166099b5f46dd33f3356b01a72c0314103a18
1 file changed +1 -3
packages/react-devtools-extensions/src/contentScripts/prepareInjection.js
+1 -3
@@ -26,10 +26,8 @@ function injectScriptSync(src) {
26 function injectScriptAsync(src) {
27 const script = document.createElement('script');
28 script.src = src;
29 - script.onload = function () {
30 - script.remove();
31 - };
29 nullthrows(document.documentElement).appendChild(script);
30 + nullthrows(script.parentNode).removeChild(script);
31 }
32
33 let lastDetectionResult;