Skip to content

Commit fcf2187

Browse files
authored
[DevTools] Remove renderer.js from extension build (#26234)
## Summary When looking into the compiled code of `installHook.js` of the extension build, I noticed that it actually includes the large `attach` function (from renderer.js). I don't think it was expected. This is because `hook.js` imports from `backend/console.js` which imports from `backend/renderer.js` for `getInternalReactConstants` A straightforward way is to extract function `getInternalReactConstants`. However, I think it's more simplified to just merge these two files and save the 361K renderer.js from the extension build since we have always been loading this code anyways. I changed the execution check from `__REACT_DEVTOOLS_ATTACH__ ` to the session storage. ## How did you test this change? Everything works normal in my local build.
1 parent b72ed69 commit fcf2187

File tree

9 files changed

+8
-54
lines changed

9 files changed

+8
-54
lines changed

packages/react-devtools-extensions/chrome/manifest.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"panel.html",
3232
"build/react_devtools_backend.js",
3333
"build/proxy.js",
34-
"build/renderer.js",
3534
"build/installHook.js"
3635
],
3736
"matches": [

packages/react-devtools-extensions/edge/manifest.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"panel.html",
3232
"build/react_devtools_backend.js",
3333
"build/proxy.js",
34-
"build/renderer.js",
3534
"build/installHook.js"
3635
],
3736
"matches": [

packages/react-devtools-extensions/firefox/manifest.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"panel.html",
3333
"build/react_devtools_backend.js",
3434
"build/proxy.js",
35-
"build/renderer.js",
3635
"build/installHook.js"
3736
],
3837
"background": {

packages/react-devtools-extensions/src/background.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ if (!IS_FIREFOX) {
2121
runAt: 'document_start',
2222
world: chrome.scripting.ExecutionWorld.MAIN,
2323
},
24-
{
25-
id: 'renderer',
26-
matches: ['<all_urls>'],
27-
js: ['build/renderer.js'],
28-
runAt: 'document_start',
29-
world: chrome.scripting.ExecutionWorld.MAIN,
30-
},
3124
],
3225
function () {
3326
// When the content scripts are already registered, an error will be thrown.

packages/react-devtools-extensions/src/contentScripts/prepareInjection.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* global chrome */
22

33
import nullthrows from 'nullthrows';
4-
import {SESSION_STORAGE_RELOAD_AND_PROFILE_KEY} from 'react-devtools-shared/src/constants';
5-
import {sessionStorageGetItem} from 'react-devtools-shared/src/storage';
64
import {IS_FIREFOX} from '../utils';
75

86
function injectScriptSync(src) {
@@ -119,11 +117,6 @@ window.addEventListener('pageshow', function ({target}) {
119117
// For Firefox, V3 is not ready, so sync injection is still the best approach.
120118
const injectScript = IS_FIREFOX ? injectScriptSync : injectScriptAsync;
121119

122-
// If we have just reloaded to profile, we need to inject the renderer interface before the app loads.
123-
if (sessionStorageGetItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true') {
124-
injectScript(chrome.runtime.getURL('build/renderer.js'));
125-
}
126-
127120
// Inject a __REACT_DEVTOOLS_GLOBAL_HOOK__ global for React to interact with.
128121
// Only do this for HTML documents though, to avoid e.g. breaking syntax highlighting for XML docs.
129122
// We need to inject this code because content scripts (ie injectGlobalHook.js) don't have access

packages/react-devtools-extensions/src/contentScripts/renderer.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

packages/react-devtools-extensions/webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ module.exports = {
5555
panel: './src/panel.js',
5656
proxy: './src/contentScripts/proxy.js',
5757
prepareInjection: './src/contentScripts/prepareInjection.js',
58-
renderer: './src/contentScripts/renderer.js',
5958
installHook: './src/contentScripts/installHook.js',
6059
},
6160
output: {

packages/react-devtools-shared/src/backend/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ export function initBackend(
7676
}
7777

7878
// Notify the DevTools frontend about new renderers.
79-
// This includes any that were attached early (via __REACT_DEVTOOLS_ATTACH__).
79+
// This includes any that were attached early
80+
// (when SESSION_STORAGE_RELOAD_AND_PROFILE_KEY is set to true).
8081
if (rendererInterface != null) {
8182
hook.emit('renderer-attached', {
8283
id,

packages/react-devtools-shared/src/hook.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import {
2121
patchConsoleUsingWindowValues,
2222
registerRenderer as registerRendererWithConsole,
2323
} from './backend/console';
24+
import {attach} from './backend/renderer';
25+
import {SESSION_STORAGE_RELOAD_AND_PROFILE_KEY} from './constants';
26+
import {sessionStorageGetItem} from './storage';
2427

2528
declare var window: any;
2629

@@ -365,8 +368,9 @@ export function installHook(target: any): DevToolsHook | null {
365368

366369
// If we have just reloaded to profile, we need to inject the renderer interface before the app loads.
367370
// Otherwise the renderer won't yet exist and we can skip this step.
368-
const attach = target.__REACT_DEVTOOLS_ATTACH__;
369-
if (typeof attach === 'function') {
371+
if (
372+
sessionStorageGetItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true'
373+
) {
370374
const rendererInterface = attach(hook, id, renderer, target);
371375
hook.rendererInterfaces.set(id, rendererInterface);
372376
}

0 commit comments

Comments
 (0)