From b06bb35ce9ca0cf283003a66db1aa079da93ad72 Mon Sep 17 00:00:00 2001 From: lauren Date: Thu, 24 Apr 2025 13:29:56 -0400 Subject: [PATCH 1/4] [forgive] Don't look up user babel configs (#33010) Projects with existing babel config files may confuse the LSP, so explictly opt out of looking them up. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33010). * #33012 * #33011 * __->__ #33010 --- compiler/packages/react-forgive/server/src/compiler/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/packages/react-forgive/server/src/compiler/index.ts b/compiler/packages/react-forgive/server/src/compiler/index.ts index 3723785cfbebd..fe192c62132b6 100644 --- a/compiler/packages/react-forgive/server/src/compiler/index.ts +++ b/compiler/packages/react-forgive/server/src/compiler/index.ts @@ -33,6 +33,8 @@ export async function compile({ plugins: ['typescript', 'jsx'], }, sourceType: 'module', + configFile: false, + babelrc: false, }); if (ast == null) { return null; @@ -48,6 +50,8 @@ export async function compile({ plugins, sourceType: 'module', sourceFileName: file, + configFile: false, + babelrc: false, }); if (result?.code == null) { throw new Error( From 2af218a7287e3ed5d41ff0ba6cb826850646f47c Mon Sep 17 00:00:00 2001 From: lauren Date: Thu, 24 Apr 2025 13:30:16 -0400 Subject: [PATCH 2/4] [forgive][ez] Tweak logging (#33011) Just some tweaks --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33011). * #33012 * __->__ #33011 * #33010 --- compiler/packages/react-forgive/server/src/index.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/packages/react-forgive/server/src/index.ts b/compiler/packages/react-forgive/server/src/index.ts index 0b43e9fcd2945..fd4ffd99886c9 100644 --- a/compiler/packages/react-forgive/server/src/index.ts +++ b/compiler/packages/react-forgive/server/src/index.ts @@ -132,7 +132,7 @@ connection.onInitialized(() => { }); documents.onDidChangeContent(async event => { - connection.console.info(`Changed: ${event.document.uri}`); + connection.console.info(`Compiling: ${event.document.uri}`); resetState(); if (SUPPORTED_LANGUAGE_IDS.has(event.document.languageId)) { const text = event.document.getText(); @@ -143,8 +143,11 @@ documents.onDidChangeContent(async event => { options: compilerOptions, }); } catch (err) { + connection.console.error('Failed to compile'); if (err instanceof Error) { - connection.console.error(err.stack ?? ''); + connection.console.error(err.stack ?? err.message); + } else { + connection.console.error(JSON.stringify(err, null, 2)); } } } @@ -192,7 +195,6 @@ connection.onCodeLensResolve(lens => { }); connection.onCodeAction(params => { - connection.console.log('onCodeAction'); const codeActions: Array = []; for (const codeActionEvent of codeActionEvents) { if ( @@ -242,6 +244,7 @@ connection.onRequest(AutoDepsDecorationsRequest.type, async params => { }); function resetState() { + connection.console.debug('Clearing state'); compiledFns.clear(); autoDepsDecorations = []; codeActionEvents = []; From 9938f83ca21f6e01e31b41ce8335a4516de276d1 Mon Sep 17 00:00:00 2001 From: lauren Date: Thu, 24 Apr 2025 13:30:36 -0400 Subject: [PATCH 3/4] [compiler] Emit CompileSkip before CompileSuccess event (#33012) Previously the CompileSuccess event would emit first before CompileSkip, so the lsp's codelens would incorrectly flag skipped components/hooks (via 'use no memo') as being optimized. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33012). * __->__ #33012 * #33011 * #33010 --- .../src/Entrypoint/Program.ts | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts b/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts index 622b7f72dad9b..34347f10b8fdf 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Program.ts @@ -469,6 +469,23 @@ export function compileProgram( } } + /** + * Otherwise if 'use no forget/memo' is present, we still run the code through the compiler + * for validation but we don't mutate the babel AST. This allows us to flag if there is an + * unused 'use no forget/memo' directive. + */ + if (pass.opts.ignoreUseNoForget === false && optOutDirectives.length > 0) { + for (const directive of optOutDirectives) { + pass.opts.logger?.logEvent(pass.filename, { + kind: 'CompileSkip', + fnLoc: fn.node.body.loc ?? null, + reason: `Skipped due to '${directive.value.value}' directive.`, + loc: directive.loc ?? null, + }); + } + return null; + } + pass.opts.logger?.logEvent(pass.filename, { kind: 'CompileSuccess', fnLoc: fn.node.loc ?? null, @@ -492,23 +509,6 @@ export function compileProgram( return null; } - /** - * Otherwise if 'use no forget/memo' is present, we still run the code through the compiler - * for validation but we don't mutate the babel AST. This allows us to flag if there is an - * unused 'use no forget/memo' directive. - */ - if (pass.opts.ignoreUseNoForget === false && optOutDirectives.length > 0) { - for (const directive of optOutDirectives) { - pass.opts.logger?.logEvent(pass.filename, { - kind: 'CompileSkip', - fnLoc: fn.node.body.loc ?? null, - reason: `Skipped due to '${directive.value.value}' directive.`, - loc: directive.loc ?? null, - }); - } - return null; - } - if (!pass.opts.noEmit) { return compileResult.compiledFn; } From 5010364d344bb5f5cc5536f5d56ed41e43b356fb Mon Sep 17 00:00:00 2001 From: lauren Date: Thu, 24 Apr 2025 13:50:03 -0400 Subject: [PATCH 4/4] [chore] Update caniuse-lite (#33013) silence annoying warnings ``` npx update-browserslist-db@latest ``` --- compiler/apps/playground/yarn.lock | 12 ++++++------ compiler/yarn.lock | 13 ++++--------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/compiler/apps/playground/yarn.lock b/compiler/apps/playground/yarn.lock index f95738b1099d2..f40fffe675519 100644 --- a/compiler/apps/playground/yarn.lock +++ b/compiler/apps/playground/yarn.lock @@ -1249,14 +1249,14 @@ camelcase-css@^2.0.1: integrity sha512-QOSvevhslijgYwRx6Rv7zKdMF8lbRmx+uQGx2+vDc+KI/eBnsy9kit5aj23AgGu3pa4t9AgwbnXWqS+iOY+2aA== caniuse-lite@^1.0.30001579: - version "1.0.30001669" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001669.tgz#fda8f1d29a8bfdc42de0c170d7f34a9cf19ed7a3" - integrity sha512-DlWzFDJqstqtIVx1zeSpIMLjunf5SmwOw0N2Ck/QSQdS8PLS4+9HrLaYei4w8BIAL7IB/UEDu889d8vhCTPA0w== + version "1.0.30001715" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001715.tgz" + integrity sha512-7ptkFGMm2OAOgvZpwgA4yjQ5SQbrNVGdRjzH0pBdy1Fasvcr+KAeECmbCAECzTuDuoX0FCY8KzUxjf9+9kfZEw== caniuse-lite@^1.0.30001646, caniuse-lite@^1.0.30001663: - version "1.0.30001664" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001664.tgz#d588d75c9682d3301956b05a3749652a80677df4" - integrity sha512-AmE7k4dXiNKQipgn7a2xg558IRqPN3jMQY/rOsbxDhrd0tyChwbITBfiwtnqz8bi2M5mIWbxAYBvk7W7QBUS2g== + version "1.0.30001715" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001715.tgz" + integrity sha512-7ptkFGMm2OAOgvZpwgA4yjQ5SQbrNVGdRjzH0pBdy1Fasvcr+KAeECmbCAECzTuDuoX0FCY8KzUxjf9+9kfZEw== chalk@^2.4.2: version "2.4.2" diff --git a/compiler/yarn.lock b/compiler/yarn.lock index 410651315da39..9e4ee0d8ca8bc 100644 --- a/compiler/yarn.lock +++ b/compiler/yarn.lock @@ -4341,15 +4341,10 @@ camelcase@^6.0.0, camelcase@^6.2.0: resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a" integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== -caniuse-lite@^1.0.30001489: - version "1.0.30001581" - resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001581.tgz" - integrity sha512-whlTkwhqV2tUmP3oYhtNfaWGYHDdS3JYFQBKXxcUR9qqPWsRhFHhoISO2Xnl/g0xyKzht9mI1LZpiNWfMzHixQ== - -caniuse-lite@^1.0.30001688: - version "1.0.30001690" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001690.tgz#f2d15e3aaf8e18f76b2b8c1481abde063b8104c8" - integrity sha512-5ExiE3qQN6oF8Clf8ifIDcMRCRE/dMGcETG/XGMD8/XiXm6HXQgQTh1yZYLXXpSOsEUlJm1Xr7kGULZTuGtP/w== +caniuse-lite@^1.0.30001489, caniuse-lite@^1.0.30001688: + version "1.0.30001715" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001715.tgz" + integrity sha512-7ptkFGMm2OAOgvZpwgA4yjQ5SQbrNVGdRjzH0pBdy1Fasvcr+KAeECmbCAECzTuDuoX0FCY8KzUxjf9+9kfZEw== chalk@2.4.2, chalk@^2.0.0, chalk@^2.4.2: version "2.4.2"