Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DevTools] Enable hook names in standalone app #22320

Merged
merged 4 commits into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/react-devtools-core/src/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ let nodeWaitingToConnectHTML: string = '';
let projectRoots: Array<string> = [];
let statusListener: StatusListener = (message: string) => {};

// TODO (Webpack 5) Hopefully we can remove this prop after the Webpack 5 migration.
function hookNamesModuleLoaderFunction() {
return import(
/* webpackChunkName: 'parseHookNames' */ 'react-devtools-shared/src/hooks/parseHookNames'
);
}

function setContentDOMNode(value: HTMLElement) {
node = value;

Expand Down Expand Up @@ -100,6 +107,7 @@ function reload() {
createElement(DevTools, {
bridge: ((bridge: any): FrontendBridge),
canViewElementSourceFunction,
hookNamesModuleLoaderFunction,
showTabBar: true,
store: ((store: any): Store),
warnIfLegacyBackendDetected: true,
Expand Down
1 change: 1 addition & 0 deletions packages/react-devtools-core/webpack.standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = {
output: {
path: __dirname + '/dist',
filename: '[name].js',
chunkFilename: '[name].chunk.js',
library: '[name]',
libraryTarget: 'commonjs2',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

export const enableProfilerChangedHookIndices = true;
export const isInternalFacebookBuild = true;
export const enableNamedHooksFeature = false;
export const enableNamedHooksFeature = true;
export const enableLogger = false;
export const consoleManagedByDevToolsDuringStrictMode = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

export const enableProfilerChangedHookIndices = false;
export const isInternalFacebookBuild = false;
export const enableNamedHooksFeature = false;
export const enableNamedHooksFeature = true;
export const enableLogger = false;
export const consoleManagedByDevToolsDuringStrictMode = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,33 +394,41 @@ function parseSourceAST(
hookParsedMetadata.originalSourceCode =
sourceMetadata.originalSourceCode;
} else {
// TypeScript is the most commonly used typed JS variant so let's default to it
// unless we detect explicit Flow usage via the "@flow" pragma.
const plugin =
originalSourceCode.indexOf('@flow') > 0 ? 'flow' : 'typescript';

// TODO (named hooks) This is probably where we should check max source length,
// rather than in loadSourceAndMetatada -> loadSourceFiles().
const originalSourceAST = withSyncPerfMeasurements(
'[@babel/parser] parse(originalSourceCode)',
() =>
parse(originalSourceCode, {
sourceType: 'unambiguous',
plugins: ['jsx', plugin],
}),
);
hookParsedMetadata.originalSourceAST = originalSourceAST;
try {
// TypeScript is the most commonly used typed JS variant so let's default to it
// unless we detect explicit Flow usage via the "@flow" pragma.
const plugin =
originalSourceCode.indexOf('@flow') > 0 ? 'flow' : 'typescript';

// TODO (named hooks) This is probably where we should check max source length,
// rather than in loadSourceAndMetatada -> loadSourceFiles().
// TODO(#22319): Support source files that are html files with inline script tags.
jstejada marked this conversation as resolved.
Show resolved Hide resolved
const originalSourceAST = withSyncPerfMeasurements(
'[@babel/parser] parse(originalSourceCode)',
() =>
parse(originalSourceCode, {
jstejada marked this conversation as resolved.
Show resolved Hide resolved
sourceType: 'unambiguous',
plugins: ['jsx', plugin],
}),
);
hookParsedMetadata.originalSourceAST = originalSourceAST;

if (__DEBUG__) {
console.log(
`parseSourceAST() Caching source metadata for "${originalSourceURL}"`,
if (__DEBUG__) {
console.log(
`parseSourceAST() Caching source metadata for "${originalSourceURL}"`,
);
}

originalURLToMetadataCache.set(originalSourceURL, {
originalSourceAST,
originalSourceCode,
});
} catch (error) {
throw new Error(
`Failed to parse source file: ${originalSourceURL}\n\n` +
`Original error: ${error}`,
);
}

originalURLToMetadataCache.set(originalSourceURL, {
originalSourceAST,
originalSourceCode,
});
}
},
);
Expand Down
1 change: 1 addition & 0 deletions packages/react-devtools/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ app.on('ready', function() {
//titleBarStyle: 'customButtonsOnHover',
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
},
});

Expand Down