Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion compiler/packages/react-mcp-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ Server Components - Shift data-heavy logic to the server whenever possible. Brea

server.tool(
'review-react-runtime',
'Review the runtime of the code and get performance data to evaluate the proposed solution, the react code that is passed into this tool MUST contain an App component.',
'Review the runtime of the code and get performance data to evaluate the proposed solution, the react code that is passed into this tool MUST contain an App functional component without arrow function. And DO NOT export anything',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add something like "run this tool every time you propose a performance related change to verify if your suggestion actually improves performance"

{
text: z.string(),
},
Expand Down
15 changes: 6 additions & 9 deletions compiler/packages/react-mcp-server/src/utils/runtimePerf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export async function measurePerformance(code: any) {
let options = {
configFile: false,
babelrc: false,
presets: [['@babel/preset-env'], '@babel/preset-react'],
presets: [require.resolve('@babel/preset-env'), require.resolve('@babel/preset-react')],
};

const parsed = await babel.parseAsync(code, options);
Expand All @@ -14,24 +14,21 @@ export async function measurePerformance(code: any) {
throw new Error('Failed to parse code');
}

const transpiled = await transformAsync(parsed);
const transpiled = await transformAsync(parsed, options);

if (!transpiled) {
throw new Error('Failed to transpile code');
}

const browser = await puppeteer.launch({
protocolTimeout: 600_000,
});
const browser = await puppeteer.launch();

const page = await browser.newPage();
await page.setViewport({width: 1280, height: 720});
const html = buildHtml(transpiled);
await page.setContent(html, {waitUntil: 'networkidle0'});

await page.waitForFunction(
'window.__RESULT__ !== undefined && (window.__RESULT__.renderTime !== null || window.__RESULT__.error !== null)',
{timeout: 600_000},
'window.__RESULT__ !== undefined && (window.__RESULT__.renderTime !== null || window.__RESULT__.error !== null)'
);

const result = await page.evaluate(() => {
Expand All @@ -48,10 +45,10 @@ export async function measurePerformance(code: any) {
* @param {Object} opts - Transformation options
* @returns {Promise<string>} - The transpiled code
*/
async function transformAsync(ast: babel.types.Node) {
async function transformAsync(ast: babel.types.Node, options: any) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can fix the any here by just removing this function and parseAsync. You can inline it directly into measurePerformance so everything is typed correctly.

const result = await babel.transformFromAstAsync(ast, undefined, {
...options,
filename: 'file.jsx',
presets: [['@babel/preset-env'], '@babel/preset-react'],
plugins: [
() => ({
visitor: {
Expand Down
Loading