mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Address comments
This commit is contained in:
1 parent
1e4614bf13
commit
ab86a5efe8
7 files changed
+71
-66
No files matched your search
+1
-1
@@ -505,7 +505,7 @@ module.exports = {
|
||||
__IS_FIREFOX__: 'readonly',
|
||||
__IS_EDGE__: 'readonly',
|
||||
__IS_NATIVE__: 'readonly',
|
||||
__IS_INTERNAL__: 'readonly',
|
||||
__IS_INTERNAL_MCP_BUILD__: 'readonly',
|
||||
__IS_INTERNAL_VERSION__: 'readonly',
|
||||
chrome: 'readonly',
|
||||
},
|
||||
|
||||
@@ -386,6 +386,8 @@ server.tool(
|
||||
url: z.string().optional().default('http://localhost:3000'),
|
||||
},
|
||||
async ({url}) => {
|
||||
|
||||
try {
|
||||
const componentTree = await parseReactComponentTree(url);
|
||||
|
||||
return {
|
||||
@@ -396,6 +398,7 @@ server.tool(
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -23,12 +23,14 @@ export async function parseReactComponentTree(url: string): Promise<string> {
|
||||
const componentTree = await localhostPage.evaluate(() => {
|
||||
return (window as any).__REACT_DEVTOOLS_GLOBAL_HOOK__.rendererInterfaces
|
||||
.get(1)
|
||||
.getComponentTree();
|
||||
.__internal_only_getComponentTree();
|
||||
});
|
||||
|
||||
return componentTree;
|
||||
} else {
|
||||
throw new Error('Localhost page not found');
|
||||
throw new Error(
|
||||
`Could not open the page at ${url}. Is your server running?`,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error('Failed extract component tree' + error);
|
||||
|
||||
@@ -72,6 +72,7 @@ module.exports = {
|
||||
__IS_CHROME__: false,
|
||||
__IS_EDGE__: false,
|
||||
__IS_NATIVE__: true,
|
||||
__IS_INTERNAL_MCP_BUILD__: false,
|
||||
'process.env.DEVTOOLS_PACKAGE': `"react-devtools-core"`,
|
||||
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
|
||||
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
|
||||
|
||||
@@ -33,7 +33,7 @@ const IS_FIREFOX = process.env.IS_FIREFOX === 'true';
|
||||
const IS_EDGE = process.env.IS_EDGE === 'true';
|
||||
const IS_INTERNAL_VERSION = process.env.FEATURE_FLAG_TARGET === 'extension-fb';
|
||||
|
||||
const IS_INTERNAL = process.env.IS_INTERNAL === 'true';
|
||||
const IS_INTERNAL_MCP_BUILD = process.env.IS_INTERNAL_MCP_BUILD === 'true';
|
||||
|
||||
const featureFlagTarget = process.env.FEATURE_FLAG_TARGET || 'extension-oss';
|
||||
|
||||
@@ -115,7 +115,7 @@ module.exports = {
|
||||
__IS_FIREFOX__: IS_FIREFOX,
|
||||
__IS_EDGE__: IS_EDGE,
|
||||
__IS_NATIVE__: false,
|
||||
__IS_INTERNAL__: IS_INTERNAL,
|
||||
__IS_INTERNAL_MCP_BUILD__: IS_INTERNAL_MCP_BUILD,
|
||||
__IS_INTERNAL_VERSION__: IS_INTERNAL_VERSION,
|
||||
'process.env.DEVTOOLS_PACKAGE': `"react-devtools-extensions"`,
|
||||
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
|
||||
|
||||
@@ -78,6 +78,7 @@ module.exports = {
|
||||
__IS_FIREFOX__: false,
|
||||
__IS_EDGE__: false,
|
||||
__IS_NATIVE__: false,
|
||||
__IS_INTERNAL_MCP_BUILD__: false,
|
||||
'process.env.DEVTOOLS_PACKAGE': `"react-devtools-inline"`,
|
||||
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
|
||||
'process.env.EDITOR_URL': EDITOR_URL != null ? `"${EDITOR_URL}"` : null,
|
||||
|
||||
+59
-61
@@ -5859,77 +5859,75 @@ export function attach(
|
||||
return unresolvedSource;
|
||||
}
|
||||
|
||||
function internal_only_getComponentTree(): string {
|
||||
let treeString = '';
|
||||
if (__IS_INTERNAL_MCP_BUILD__) {
|
||||
function __internal_only_getComponentTree(): string {
|
||||
let treeString = '';
|
||||
|
||||
function buildTreeString(
|
||||
instance: DevToolsInstance,
|
||||
prefix: string = '',
|
||||
isLastChild: boolean = true,
|
||||
): void {
|
||||
if (!instance) return;
|
||||
function buildTreeString(
|
||||
instance: DevToolsInstance,
|
||||
prefix: string = '',
|
||||
isLastChild: boolean = true,
|
||||
): void {
|
||||
if (!instance) return;
|
||||
|
||||
const name =
|
||||
(instance.kind !== VIRTUAL_INSTANCE
|
||||
? getDisplayNameForFiber(instance.data)
|
||||
: instance.data.name) || 'Unknown';
|
||||
const name =
|
||||
(instance.kind !== VIRTUAL_INSTANCE
|
||||
? getDisplayNameForFiber(instance.data)
|
||||
: instance.data.name) || 'Unknown';
|
||||
|
||||
const id = instance.id !== undefined ? instance.id : 'unknown';
|
||||
const id = instance.id !== undefined ? instance.id : 'unknown';
|
||||
|
||||
if (name !== 'createRoot()') {
|
||||
treeString +=
|
||||
prefix +
|
||||
(isLastChild ? '└── ' : '├── ') +
|
||||
name +
|
||||
' (id: ' +
|
||||
id +
|
||||
')\n';
|
||||
}
|
||||
if (name !== 'createRoot()') {
|
||||
treeString +=
|
||||
prefix +
|
||||
(isLastChild ? '└── ' : '├── ') +
|
||||
name +
|
||||
' (id: ' +
|
||||
id +
|
||||
')\n';
|
||||
}
|
||||
|
||||
const childPrefix = prefix + (isLastChild ? ' ' : '│ ');
|
||||
const childPrefix = prefix + (isLastChild ? ' ' : '│ ');
|
||||
|
||||
let childCount = 0;
|
||||
let tempChild = instance.firstChild;
|
||||
while (tempChild !== null) {
|
||||
childCount++;
|
||||
tempChild = tempChild.nextSibling;
|
||||
}
|
||||
let childCount = 0;
|
||||
let tempChild = instance.firstChild;
|
||||
while (tempChild !== null) {
|
||||
childCount++;
|
||||
tempChild = tempChild.nextSibling;
|
||||
}
|
||||
|
||||
let child = instance.firstChild;
|
||||
let currentChildIndex = 0;
|
||||
let child = instance.firstChild;
|
||||
let currentChildIndex = 0;
|
||||
|
||||
while (child !== null) {
|
||||
currentChildIndex++;
|
||||
const isLastSibling = currentChildIndex === childCount;
|
||||
buildTreeString(child, childPrefix, isLastSibling);
|
||||
child = child.nextSibling;
|
||||
}
|
||||
}
|
||||
|
||||
const rootInstances: Array<DevToolsInstance> = [];
|
||||
idToDevToolsInstanceMap.forEach(instance => {
|
||||
if (
|
||||
instance.parent === null ||
|
||||
(instance.parent.kind === FILTERED_FIBER_INSTANCE &&
|
||||
instance.parent.parent === null)
|
||||
) {
|
||||
rootInstances.push(instance);
|
||||
}
|
||||
});
|
||||
|
||||
if (rootInstances.length > 0) {
|
||||
for (let i = 0; i < rootInstances.length; i++) {
|
||||
const isLast = i === rootInstances.length - 1;
|
||||
buildTreeString(rootInstances[i], '', isLast);
|
||||
if (!isLast) {
|
||||
treeString += '\n';
|
||||
while (child !== null) {
|
||||
currentChildIndex++;
|
||||
const isLastSibling = currentChildIndex === childCount;
|
||||
buildTreeString(child, childPrefix, isLastSibling);
|
||||
child = child.nextSibling;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
treeString = 'No component tree found.';
|
||||
}
|
||||
|
||||
return treeString;
|
||||
const rootInstances: Array<DevToolsInstance> = [];
|
||||
idToDevToolsInstanceMap.forEach(instance => {
|
||||
if (instance.parent === null || instance.parent.parent === null) {
|
||||
rootInstances.push(instance);
|
||||
}
|
||||
});
|
||||
|
||||
if (rootInstances.length > 0) {
|
||||
for (let i = 0; i < rootInstances.length; i++) {
|
||||
const isLast = i === rootInstances.length - 1;
|
||||
buildTreeString(rootInstances[i], '', isLast);
|
||||
if (!isLast) {
|
||||
treeString += '\n';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
treeString = 'No component tree found.';
|
||||
}
|
||||
|
||||
return treeString;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -5946,7 +5944,7 @@ export function attach(
|
||||
getNearestMountedDOMNode,
|
||||
getElementIDForHostInstance,
|
||||
getInstanceAndStyle,
|
||||
...(__IS_INTERNAL__ && {internal_only_getComponentTree}),
|
||||
...(__IS_INTERNAL_MCP_BUILD__ && {__internal_only_getComponentTree}),
|
||||
getOwnersList,
|
||||
getPathForElement,
|
||||
getProfilingData,
|
||||
|
||||
Reference in new issue
Block a user