Skip to content

Commit 7e2d7bb

Browse files
author
Juan Tejada
committed
[DevTools] Enable hook names in standalone app
1 parent 50263d3 commit 7e2d7bb

File tree

9 files changed

+64
-28
lines changed

9 files changed

+64
-28
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./dist/hookNames');

packages/react-devtools-core/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"dist",
1414
"backend.js",
1515
"build-info.json",
16-
"standalone.js"
16+
"standalone.js",
17+
"hookNames.js"
1718
],
1819
"scripts": {
1920
"build": "yarn build:backend && yarn build:standalone",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import {
11+
parseHookNames,
12+
parseSourceAndMetadata,
13+
purgeCachedMetadata,
14+
} from 'react-devtools-shared/src/hooks/parseHookNames';
15+
16+
export {parseHookNames, parseSourceAndMetadata, purgeCachedMetadata};

packages/react-devtools-core/src/standalone.js

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ let nodeWaitingToConnectHTML: string = '';
4343
let projectRoots: Array<string> = [];
4444
let statusListener: StatusListener = (message: string) => {};
4545

46+
// TODO (Webpack 5) Hopefully we can remove this prop after the Webpack 5 migration.
47+
function hookNamesModuleLoaderFunction() {
48+
return import('./hookNames');
49+
}
50+
4651
function setContentDOMNode(value: HTMLElement) {
4752
node = value;
4853

@@ -100,6 +105,7 @@ function reload() {
100105
createElement(DevTools, {
101106
bridge: ((bridge: any): FrontendBridge),
102107
canViewElementSourceFunction,
108+
hookNamesModuleLoaderFunction,
103109
showTabBar: true,
104110
store: ((store: any): Store),
105111
warnIfLegacyBackendDetected: true,

packages/react-devtools-core/webpack.standalone.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ const babelOptions = {
3838

3939
module.exports = {
4040
mode: __DEV__ ? 'development' : 'production',
41-
devtool: __DEV__ ? 'cheap-module-eval-source-map' : 'source-map',
41+
devtool: __DEV__ ? 'cheap-source-map' : 'source-map',
4242
target: 'electron-main',
4343
entry: {
4444
standalone: './src/standalone.js',
45+
hookNames: './src/hookNames.js',
4546
},
4647
output: {
4748
path: __dirname + '/dist',
4849
filename: '[name].js',
50+
chunkFilename: '[name].chunk.js',
4951
library: '[name]',
5052
libraryTarget: 'commonjs2',
5153
},

packages/react-devtools-shared/src/config/DevToolsFeatureFlags.core-fb.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
export const enableProfilerChangedHookIndices = true;
1717
export const isInternalFacebookBuild = true;
18-
export const enableNamedHooksFeature = false;
18+
export const enableNamedHooksFeature = true;
1919
export const enableLogger = false;
2020
export const consoleManagedByDevToolsDuringStrictMode = false;
2121

packages/react-devtools-shared/src/config/DevToolsFeatureFlags.core-oss.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
export const enableProfilerChangedHookIndices = false;
1717
export const isInternalFacebookBuild = false;
18-
export const enableNamedHooksFeature = false;
18+
export const enableNamedHooksFeature = true;
1919
export const enableLogger = false;
2020
export const consoleManagedByDevToolsDuringStrictMode = false;
2121

packages/react-devtools-shared/src/hooks/parseHookNames/parseSourceAndMetadata.js

+33-24
Original file line numberDiff line numberDiff line change
@@ -394,33 +394,42 @@ function parseSourceAST(
394394
hookParsedMetadata.originalSourceCode =
395395
sourceMetadata.originalSourceCode;
396396
} else {
397-
// TypeScript is the most commonly used typed JS variant so let's default to it
398-
// unless we detect explicit Flow usage via the "@flow" pragma.
399-
const plugin =
400-
originalSourceCode.indexOf('@flow') > 0 ? 'flow' : 'typescript';
401-
402-
// TODO (named hooks) This is probably where we should check max source length,
403-
// rather than in loadSourceAndMetatada -> loadSourceFiles().
404-
const originalSourceAST = withSyncPerfMeasurements(
405-
'[@babel/parser] parse(originalSourceCode)',
406-
() =>
407-
parse(originalSourceCode, {
408-
sourceType: 'unambiguous',
409-
plugins: ['jsx', plugin],
410-
}),
411-
);
412-
hookParsedMetadata.originalSourceAST = originalSourceAST;
397+
try {
398+
// TypeScript is the most commonly used typed JS variant so let's default to it
399+
// unless we detect explicit Flow usage via the "@flow" pragma.
400+
const plugin =
401+
originalSourceCode.indexOf('@flow') > 0 ? 'flow' : 'typescript';
402+
403+
// TODO (named hooks) This is probably where we should check max source length,
404+
// rather than in loadSourceAndMetatada -> loadSourceFiles().
405+
// TODO(#22319): Support source files that are html files with inline script tags.
406+
const originalSourceAST = withSyncPerfMeasurements(
407+
'[@babel/parser] parse(originalSourceCode)',
408+
() =>
409+
parse(originalSourceCode, {
410+
errorRecovery: true,
411+
sourceType: 'unambiguous',
412+
plugins: ['jsx', plugin],
413+
}),
414+
);
415+
hookParsedMetadata.originalSourceAST = originalSourceAST;
413416

414-
if (__DEBUG__) {
415-
console.log(
416-
`parseSourceAST() Caching source metadata for "${originalSourceURL}"`,
417+
if (__DEBUG__) {
418+
console.log(
419+
`parseSourceAST() Caching source metadata for "${originalSourceURL}"`,
420+
);
421+
}
422+
423+
originalURLToMetadataCache.set(originalSourceURL, {
424+
originalSourceAST,
425+
originalSourceCode,
426+
});
427+
} catch (error) {
428+
throw new Error(
429+
`Failed to parse source file: ${originalSourceURL}\n\n` +
430+
`Original error: ${error}`,
417431
);
418432
}
419-
420-
originalURLToMetadataCache.set(originalSourceURL, {
421-
originalSourceAST,
422-
originalSourceCode,
423-
});
424433
}
425434
},
426435
);

packages/react-devtools/app.js

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ app.on('ready', function() {
3030
//titleBarStyle: 'customButtonsOnHover',
3131
webPreferences: {
3232
nodeIntegration: true,
33+
nodeIntegrationInWorker: true,
3334
},
3435
});
3536

0 commit comments

Comments
 (0)