-
Notifications
You must be signed in to change notification settings - Fork 5.4k
build: Enable React Compiler for Webpack builds #38007
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
Open
MajorLift
wants to merge
123
commits into
main
Choose a base branch
from
jongsun/build/enable-react-compiler-webpack
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+233
−11
Open
Changes from all commits
Commits
Show all changes
123 commits
Select commit
Hold shift + click to select a range
9b4cd28
Set `react-hooks/rules-of-hooks` eslint ruleset to "error"
MajorLift af51e2b
Fix `rules-of-hooks` violations
MajorLift c53e435
Rename: `{s,useS}etConfirmationAlerts`
MajorLift 0e10ad7
Add `eslint-disable` directives for `rules-of-hooks`
MajorLift d3c1f6e
Rename: `{s,useS}yncConfirmPath`
MajorLift 4abb021
Merge branch 'main' into jongsun/chore/251030-enable-rules-of-hooks
MajorLift da42adc
Fix conditional hook calls introduced from main
MajorLift 8fd5794
Fix incorrectly resolved merge conflict
MajorLift 8933eb6
Set up React Compiler
MajorLift 435d46f
Fix formatting rule violations
MajorLift 3d6ddc1
Fix logical rule violations
MajorLift 8f719cb
Fix breakages
MajorLift 3520c5b
Merge branch 'main' into jongsun/chore/251030-enable-rules-of-hooks
MajorLift 81d2550
Merge branch 'main' into jongsun/chore/251030-enable-rules-of-hooks
MajorLift a416f2c
Refactor webpack config to have dedicated loader for react compiler
MajorLift e1020cf
Fix lint regression
MajorLift 26474c8
Fix regression from main
MajorLift 885d97d
Fix webpack react compiler loader option object type
MajorLift d2fa283
Fix incorrectly resolved merge conflict
MajorLift 8983be0
Use exact versions for react compiler deps
MajorLift 148a3e1
Merge branch 'jongsun/chore/251030-enable-rules-of-hooks' into jongsu…
MajorLift ca4e8e2
More fixes
MajorLift 958e912
Merge branch 'jongsun/chore/251030-enable-rules-of-hooks' into jongsu…
MajorLift d816c82
Rename `{use,handle}SnapNavigate`
MajorLift b64d7db
lavamoat: Widen `process` nested globals access to top-level scope
MajorLift 2b2fdb4
Update LavaMoat policies
metamaskbot 1a87ae8
Fix ui path in webpack loader
MajorLift 7ed0746
Update LavaMoat policies
metamaskbot 287d5b9
Remove source path exceptions
MajorLift 64a540d
test: Update unit test snapshot
MajorLift 300cdf0
Exclude `typed-sign-permission-util.ts`
MajorLift 2672f02
Fix error from missing `t` in dep array
MajorLift 57b3a75
Fix "Should have a queue" error by opting-out `ui/pages/confirmations…
MajorLift b4be12a
Merge branch 'main' into jongsun/build/251103-enable-react-compiler
MajorLift a07e1b4
Opt-out regression from main
MajorLift 4fa7ca9
Fix incorrect mounting logic
MajorLift c7683cd
Remove unnecessary key prop
MajorLift db50bc8
Fix build config
MajorLift 9c7180f
Merge branch 'main' into jongsun/build/251103-enable-react-compiler
MajorLift a51fdb7
Update LavaMoat policies
metamaskbot d3453be
Merge branch 'main' into jongsun/build/251103-enable-react-compiler
MajorLift 11a605d
Opt-outs
MajorLift 6439755
Add excluded paths
MajorLift 3c917a3
Add react compiler logger for webpack
MajorLift 5e908de
Merge branch 'main' into jongsun/build/251103-enable-react-compiler
MajorLift fae3b64
Update LavaMoat policies
metamaskbot 8ac83e8
Revert webpack config
MajorLift 01c9906
Merge branch 'main' into jongsun/build/251103-enable-react-compiler
MajorLift dbe4c7d
Remove `exhaustive-deps` regression from main
MajorLift 9ed8bca
Update LavaMoat policies
metamaskbot 8521341
Remove `component-library` from excluded paths
MajorLift 1b20e16
Remove webpack entry in `.depcheckrc`
MajorLift 3cd3634
Merge branch 'main' into jongsun/build/251103-enable-react-compiler
MajorLift 249d0ea
Fix faulty fallback logic for confirm alerts state keys
MajorLift 931a675
Bump deps to v1.0
MajorLift d5ab272
Fix `useAsync` mounted check race condition
MajorLift 1339d5c
Add entry to exclude patterns
MajorLift 9916a99
Update LavaMoat policies
metamaskbot 4905214
Install `react-compiler-webpack` as devDep
MajorLift f7d168f
Add to depcheck ignore list
MajorLift 44d68c3
Update LavaMoat policies
MajorLift cfbcdc2
Set up webpack config with react compiler loader
MajorLift 9945b27
Bump `react-compiler-webpack` to `^1.0.0`
MajorLift 94e10c8
Add deps
MajorLift 66aba3d
Fix HOC-returned component local name
MajorLift e839433
Opt-out `useTokenExchangeRate`
MajorLift d919782
Use regex instead of array iteration to filter paths for react compil…
MajorLift d0ea0c7
Fix `UI_DIR_RE` to only match top-level `ui/` dir
MajorLift 92453b4
Make regex groups non-capturing
MajorLift 8a491bc
Fix `renderHook` usage in test
MajorLift 2576d4f
Refactor babel config to register react compiler as an override
MajorLift 9595d1e
Remove redundant node_modules exclude
MajorLift 3ac0d1c
Fix regex
MajorLift e456d36
Dedupe lockfile
MajorLift 659c749
Revert "Fix regex"
MajorLift b17086f
Revert "Dedupe lockfile"
MajorLift a5acea4
Make regex non-capturing
MajorLift d0321db
Merge branch 'main' into jongsun/build/251103-enable-react-compiler
MajorLift 54d4402
Merge branch 'jongsun/build/251103-enable-react-compiler' into jongsu…
MajorLift addb658
Define `reactCompilerLoader`, `ReactCompilerLogger`
MajorLift 9b0611f
Add `reactCompilerVerbose` cli argument
MajorLift 68e28d9
Set up loader, logger in webpack config
MajorLift 5723799
Merge branch 'jongsun/build/webpack/react-compiler-debug-mode' into j…
MajorLift e790a49
Update webpack-cli test mock
MajorLift e0e62a9
Stricter regex for `ui/`
MajorLift f744056
Add comments
MajorLift 713aa39
Fix babel config regex to only match top-level `ui/`
MajorLift 79d9bf8
Define `--reactCompilerDebug` webpack build argument that sets `panic…
MajorLift 763f814
Less ambiguous regex
MajorLift af600fc
Merge branch 'jongsun/build/251103-enable-react-compiler' into jongsu…
MajorLift 478ac1d
Bump `tsx` from `^4.19.2` to `^4.20.6`
MajorLift 0a7f8d6
Merge branch 'main' into jongsun/build/251103-enable-react-compiler
MajorLift f2430ed
Merge branch 'jongsun/build/251103-enable-react-compiler' into jongsu…
MajorLift 241d541
Update LavaMoat policies
metamaskbot a9ce8e9
Update LavaMoat policies
metamaskbot 663a07b
Bump `koa` from `^2.7.0` to `^3.1.1`
MajorLift 21df361
Merge branch 'jongsun/build/251103-enable-react-compiler' into jongsu…
MajorLift 08d667a
Update LavaMoat policies
metamaskbot 1144cb8
Update LavaMoat policies
metamaskbot f5674d5
Fix regex
MajorLift 8fad14e
Merge branch 'jongsun/build/251103-enable-react-compiler' into jongsu…
MajorLift ec850a1
Dedupe lockfile
MajorLift 97ebb74
Update LavaMoat policies
metamaskbot 3bf814e
Fix regex
MajorLift ef0fb23
Set debug mode option default to 'none'
MajorLift 30f49be
Add entries to dry run message
MajorLift 01094ea
Remove unnecessary cleanup
MajorLift 7969aa6
Opt-out confirm alert files
MajorLift 6788b0f
Revert `in` property check
MajorLift 189e390
Revert handling for `background[method]` not function error
MajorLift be6e749
Add missing background method mock
MajorLift dda7ecb
Opt-out `useAssetMetadata`
MajorLift 2455a12
Merge branch 'main' into jongsun/build/251103-enable-react-compiler
MajorLift 88afa9e
Merge branch 'jongsun/build/251103-enable-react-compiler' into jongsu…
MajorLift 9e269b9
Remove opt-out from root
MajorLift 7266050
Merge branch 'jongsun/build/251103-enable-react-compiler' into jongsu…
MajorLift 4670591
Merge branch 'main' into jongsun/build/enable-react-compiler-webpack
MajorLift fd55bb2
Update LavaMoat policies
metamaskbot 386e351
Dedupe lockfile
MajorLift 83cf846
Update LavaMoat policies
metamaskbot 09a7259
Group new CLI arguments with other developer assistance entries in `g…
MajorLift 11f0f4b
Merge branch 'main' into jongsun/build/enable-react-compiler-webpack
MajorLift b6992a0
Define `ReactCompilerPlugin`
MajorLift File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
development/webpack/utils/loaders/reactCompilerLoader.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| import { | ||
| type ReactCompilerLoaderOption, | ||
| defineReactCompilerLoaderOption, | ||
| reactCompilerLoader, | ||
| } from 'react-compiler-webpack'; | ||
| import type { Logger } from 'babel-plugin-react-compiler'; | ||
|
|
||
| /** | ||
| * React Compiler logger that tracks compilation statistics | ||
| */ | ||
| class ReactCompilerLogger { | ||
| private compiledCount = 0; | ||
|
|
||
| private skippedCount = 0; | ||
|
|
||
| private errorCount = 0; | ||
|
|
||
| private todoCount = 0; | ||
|
|
||
| private compiledFiles: string[] = []; | ||
|
|
||
| private skippedFiles: string[] = []; | ||
|
|
||
| private errorFiles: string[] = []; | ||
|
|
||
| private todoFiles: string[] = []; | ||
|
|
||
| logEvent( | ||
| filename: string | null, | ||
| event: { kind: string; detail: { options: { category: string } } }, | ||
| ) { | ||
| if (filename === null) { | ||
| return; | ||
| } | ||
| const { options: errorDetails } = event.detail ?? {}; | ||
| switch (event.kind) { | ||
| case 'CompileSuccess': | ||
| this.compiledCount++; | ||
| this.compiledFiles.push(filename); | ||
| console.log(`✅ Compiled: ${filename}`); | ||
| break; | ||
| case 'CompileSkip': | ||
| this.skippedCount++; | ||
| this.skippedFiles.push(filename); | ||
| break; | ||
| case 'CompileError': | ||
| // This error is thrown for syntax that is not yet supported by the React Compiler. | ||
| // We count these separately as "unsupported" errors, since there's no actionable fix we can apply. | ||
| if (errorDetails?.category === 'Todo') { | ||
| this.todoCount++; | ||
| this.todoFiles.push(filename); | ||
| break; | ||
| } | ||
| this.errorCount++; | ||
| this.errorFiles.push(filename); | ||
| console.error( | ||
| `❌ React Compiler error in ${filename}: ${errorDetails ? JSON.stringify(errorDetails) : 'Unknown error'}`, | ||
| ); | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| getStats() { | ||
| return { | ||
| compiled: this.compiledCount, | ||
| skipped: this.skippedCount, | ||
| errors: this.errorCount, | ||
| unsupported: this.todoCount, | ||
| total: | ||
| this.compiledCount + | ||
| this.skippedCount + | ||
| this.errorCount + | ||
| this.todoCount, | ||
| compiledFiles: this.compiledFiles, | ||
| skippedFiles: this.skippedFiles, | ||
| errorFiles: this.errorFiles, | ||
| unsupportedFiles: this.todoFiles, | ||
| }; | ||
| } | ||
|
|
||
| logSummary() { | ||
| const stats = this.getStats(); | ||
| console.log('\n📊 React Compiler Statistics:'); | ||
| console.log(` ✅ Compiled: ${stats.compiled} files`); | ||
| console.log(` ⏭️ Skipped: ${stats.skipped} files`); | ||
| console.log(` ❌ Errors: ${stats.errors} files`); | ||
| console.log(` 🔍 Unsupported: ${stats.unsupported} files`); | ||
| console.log(` 📦 Total processed: ${stats.total} files`); | ||
| } | ||
| } | ||
|
|
||
| const reactCompilerLogger = new ReactCompilerLogger(); | ||
|
|
||
| /** | ||
| * Get the React Compiler logger singleton instance to access statistics. | ||
| */ | ||
| export function getReactCompilerLogger(): ReactCompilerLogger { | ||
| return reactCompilerLogger; | ||
| } | ||
|
|
||
| /** | ||
| * Get the React Compiler loader. | ||
| * | ||
| * @param target - The target version of the React Compiler. | ||
| * @param verbose - Whether to enable verbose mode. | ||
| * @param debug - The debug level to use. | ||
| * - 'all': Fail build on and display debug information for all compilation errors. | ||
| * - 'critical': Fail build on and display debug information only for critical compilation errors. | ||
| * - 'none': Prevent build from failing. | ||
| * @returns The React Compiler loader object with the loader and configured options. | ||
| */ | ||
| export const getReactCompilerLoader = ( | ||
| target: ReactCompilerLoaderOption['target'], | ||
| verbose: boolean, | ||
| debug: 'all' | 'critical' | 'none', | ||
| ) => { | ||
| const reactCompilerOptions = { | ||
| target, | ||
| logger: verbose ? (reactCompilerLogger as Logger) : undefined, | ||
| panicThreshold: debug === 'none' ? debug : `${debug}_errors`, | ||
| } as const satisfies ReactCompilerLoaderOption; | ||
|
|
||
| return { | ||
| loader: reactCompilerLoader, | ||
| options: defineReactCompilerLoaderOption(reactCompilerOptions), | ||
| }; | ||
| }; |
11 changes: 11 additions & 0 deletions
11
development/webpack/utils/plugins/ReactCompilerPlugin/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import type { Compiler } from 'webpack'; | ||
| import { getReactCompilerLogger } from '../../loaders/reactCompilerLoader'; | ||
|
|
||
| export class ReactCompilerPlugin { | ||
| apply(compiler: Compiler): void { | ||
| compiler.hooks.afterEmit.tap(ReactCompilerPlugin.name, () => { | ||
| const logger = getReactCompilerLogger(); | ||
| logger.logSummary(); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: UI_DIR_RE path construction misses app directory
The
UI_DIR_REregex resolves to/path/to/metamask-extension/ui/..., but webpack serves files from/path/to/metamask-extension/app/ui/.... The path construction injoin(__dirname, '../../../')should bejoin(__dirname, '../../../../app/')to correctly match the webpack context where files are actually located.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not true in our project.