From 564166099b5f46dd33f3356b01a72c0314103a18 Mon Sep 17 00:00:00 2001 From: Mengdi Chen Date: Fri, 24 Feb 2023 15:13:05 -0500 Subject: [PATCH] [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. --- .../src/contentScripts/prepareInjection.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/react-devtools-extensions/src/contentScripts/prepareInjection.js b/packages/react-devtools-extensions/src/contentScripts/prepareInjection.js index b5d667d26254a..4ab0500f59ddb 100644 --- a/packages/react-devtools-extensions/src/contentScripts/prepareInjection.js +++ b/packages/react-devtools-extensions/src/contentScripts/prepareInjection.js @@ -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;