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

make parseHookNames a separate bundle #22102

Merged
merged 1 commit into from
Aug 16, 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
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('parseHookNames', () => {

inspectHooks = require('react-debug-tools/src/ReactDebugHooks')
.inspectHooks;
parseHookNames = require('../parseHookNames').parseHookNames;
parseHookNames = require('../parseHookNames/parseHookNames').parseHookNames;

// Jest (jest-runner?) configures Errors to automatically account for source maps.
// This changes behavior between our tests and the browser.
Expand Down Expand Up @@ -718,22 +718,13 @@ describe('parseHookNames', () => {
describe('parseHookNames worker', () => {
let inspectHooks;
let parseHookNames;
let originalParseHookNamesMock;
let workerizedParseHookNamesMock;

beforeEach(() => {
window.Worker = undefined;

originalParseHookNamesMock = jest.fn();
workerizedParseHookNamesMock = jest.fn();

jest.mock('../parseHookNames/parseHookNames.js', () => {
return {
__esModule: true,
parseHookNames: originalParseHookNamesMock,
};
});

jest.mock('../parseHookNames/parseHookNames.worker.js', () => {
return {
__esModule: true,
Expand All @@ -757,7 +748,7 @@ describe('parseHookNames worker', () => {
return hookNames;
}

it('should use worker when available', async () => {
it('should use worker', async () => {
const Component = require('./__source__/__untransformed__/ComponentWithUseState')
.Component;

Expand All @@ -769,13 +760,4 @@ describe('parseHookNames worker', () => {
await getHookNamesForComponent(Component);
expect(workerizedParseHookNamesMock).toHaveBeenCalledTimes(1);
});

it('should use main thread when worker is not available', async () => {
const Component = require('./__source__/__untransformed__/ComponentWithUseState')
.Component;

await getHookNamesForComponent(Component);
expect(workerizedParseHookNamesMock).toHaveBeenCalledTimes(0);
expect(originalParseHookNamesMock).toHaveBeenCalledTimes(1);
});
});
38 changes: 20 additions & 18 deletions packages/react-devtools-extensions/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
getSavedComponentFilters,
getShowInlineWarningsAndErrors,
} from 'react-devtools-shared/src/utils';
import {parseHookNames, purgeCachedMetadata} from './parseHookNames';
import {
localStorageGetItem,
localStorageRemoveItem,
Expand Down Expand Up @@ -210,23 +209,26 @@ function createPanelIfReactLoaded() {

render = (overrideTab = mostRecentOverrideTab) => {
mostRecentOverrideTab = overrideTab;

root.render(
jstejada marked this conversation as resolved.
Show resolved Hide resolved
createElement(DevTools, {
bridge,
browserTheme: getBrowserTheme(),
componentsPortalContainer,
enabledInspectedElementContextMenu: true,
loadHookNames: parseHookNames,
overrideTab,
profilerPortalContainer,
purgeCachedHookNamesMetadata: purgeCachedMetadata,
showTabBar: false,
store,
warnIfUnsupportedVersionDetected: true,
viewAttributeSourceFunction,
viewElementSourceFunction,
}),
import('./parseHookNames').then(
jstejada marked this conversation as resolved.
Show resolved Hide resolved
({parseHookNames, purgeCachedMetadata}) => {
root.render(
createElement(DevTools, {
bridge,
browserTheme: getBrowserTheme(),
componentsPortalContainer,
enabledInspectedElementContextMenu: true,
loadHookNames: parseHookNames,
overrideTab,
profilerPortalContainer,
purgeCachedHookNamesMetadata: purgeCachedMetadata,
showTabBar: false,
store,
warnIfUnsupportedVersionDetected: true,
viewAttributeSourceFunction,
viewElementSourceFunction,
}),
);
},
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@
// This file uses workerize to load ./parseHookNames.worker as a webworker and instanciates it,
// exposing flow typed functions that can be used on other files.

import * as parseHookNamesModule from './parseHookNames';
import WorkerizedParseHookNames from './parseHookNames.worker';

type ParseHookNamesModule = typeof parseHookNamesModule;
import typeof * as ParseHookNamesModule from './parseHookNames';

// $FlowFixMe
const wasmMappingsURL = chrome.extension.getURL('mappings.wasm');

const workerizedParseHookNames: ParseHookNamesModule = window.Worker
? WorkerizedParseHookNames()
: parseHookNamesModule;
const workerizedParseHookNames: ParseHookNamesModule = WorkerizedParseHookNames();

type ParseHookNames = $PropertyType<ParseHookNamesModule, 'parseHookNames'>;

Expand Down
1 change: 1 addition & 0 deletions packages/react-devtools-extensions/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = {
},
output: {
path: __dirname + '/build',
publicPath: '/build/',
jstejada marked this conversation as resolved.
Show resolved Hide resolved
filename: '[name].js',
},
node: {
Expand Down