Skip to content

Commit 0245a73

Browse files
committed
stash
1 parent 1339d5c commit 0245a73

File tree

13 files changed

+207
-19
lines changed

13 files changed

+207
-19
lines changed

.depcheckrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ ignores:
8282
- 'path-browserify' # polyfill
8383
- 'nyc' # coverage
8484
- 'core-js-pure' # polyfills
85+
- 'react-compiler-webpack' # build tool
8586
# babel
8687
- '@babel/plugin-transform-logical-assignment-operators'
8788
- 'babel-plugin-react-compiler'

development/webpack/utils/config.ts

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { join } from 'node:path';
22
import { readFileSync } from 'node:fs';
33
import { parse } from 'dotenv';
4+
import type { ReactCompilerLoaderOption } from 'react-compiler-webpack';
5+
import type { EnvironmentConfig } from 'babel-plugin-react-compiler';
46
import { setEnvironmentVariables } from '../../build/set-environment-variables';
57
import type { Variables } from '../../lib/variables';
68
import type { BuildTypesConfig, BuildType } from '../../lib/build-type';
@@ -189,3 +191,117 @@ function loadConfigVars(
189191

190192
return definitions;
191193
}
194+
195+
/**
196+
* React Compiler logger that tracks compilation statistics
197+
*/
198+
class ReactCompilerLogger {
199+
private compiledCount = 0;
200+
201+
private skippedCount = 0;
202+
203+
private errorCount = 0;
204+
205+
private compiledFiles: string[] = [];
206+
207+
private skippedFiles: string[] = [];
208+
209+
private errorFiles: string[] = [];
210+
211+
logEvent(filename: string | null, event: { kind: string; reason?: string }) {
212+
if (filename === null) {
213+
return;
214+
}
215+
switch (event.kind) {
216+
case 'CompileSuccess':
217+
this.compiledCount++;
218+
this.compiledFiles.push(filename);
219+
// console.log(`✅ Compiled: ${filename}`);
220+
break;
221+
case 'CompileSkip':
222+
this.skippedCount++;
223+
this.skippedFiles.push(filename);
224+
break;
225+
case 'CompileError':
226+
this.errorCount++;
227+
this.errorFiles.push(filename);
228+
// console.error(
229+
// `❌ React Compiler error in ${filename}: ${event.reason || 'Unknown error'}`,
230+
// );
231+
break;
232+
default:
233+
// Ignore other event types
234+
break;
235+
}
236+
}
237+
238+
getStats() {
239+
return {
240+
compiled: this.compiledCount,
241+
skipped: this.skippedCount,
242+
errors: this.errorCount,
243+
total: this.compiledCount + this.skippedCount + this.errorCount,
244+
compiledFiles: this.compiledFiles,
245+
skippedFiles: this.skippedFiles,
246+
errorFiles: this.errorFiles,
247+
};
248+
}
249+
250+
logSummary() {
251+
const stats = this.getStats();
252+
console.log('\n📊 React Compiler Statistics:');
253+
console.log(` ✅ Compiled: ${stats.compiled} files`);
254+
console.log(` ⏭️ Skipped: ${stats.skipped} files`);
255+
console.log(` ❌ Errors: ${stats.errors} files`);
256+
console.log(` 📦 Total processed: ${stats.total} files`);
257+
}
258+
}
259+
260+
// Create a singleton logger instance
261+
const reactCompilerLogger = new ReactCompilerLogger();
262+
263+
export const reactCompilerOptions = {
264+
target: '17',
265+
logger: reactCompilerLogger,
266+
gating: null,
267+
noEmit: false,
268+
compilationMode: 'all',
269+
eslintSuppressionRules: null,
270+
flowSuppressions: false,
271+
ignoreUseNoForget: false,
272+
sources: (filename) => {
273+
if (!filename.includes('/ui/')) {
274+
return false;
275+
}
276+
const excludePatterns = [
277+
'.test.',
278+
'.stories.',
279+
'.container.',
280+
'/ui/index.js',
281+
'/__mocks__/',
282+
'/__snapshots__/',
283+
'/constants/',
284+
'/helpers/',
285+
'/ducks/',
286+
'/selectors/',
287+
'/store/',
288+
'/component-library/',
289+
];
290+
if (excludePatterns.some((pattern) => filename.includes(pattern))) {
291+
return false;
292+
}
293+
return true;
294+
},
295+
enableReanimatedCheck: false,
296+
environment: {} as EnvironmentConfig,
297+
dynamicGating: null,
298+
panicThreshold: 'none',
299+
customOptOutDirectives: null,
300+
} as const satisfies ReactCompilerLoaderOption;
301+
302+
/**
303+
* Get the React Compiler logger instance for accessing statistics
304+
*/
305+
export function getReactCompilerLogger(): ReactCompilerLogger {
306+
return reactCompilerLogger;
307+
}

development/webpack/utils/loaders/swcLoader.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { sep } from 'node:path';
21
import type { LoaderContext } from 'webpack';
32
import { type JSONSchema7 } from 'schema-utils/declarations/validate';
43
import { validate } from 'schema-utils';
@@ -173,23 +172,15 @@ type SchemaOptions = { keepDefaultedPropertiesOptional: true };
173172
export type SwcLoaderOptions = FromSchema<typeof schema, SchemaOptions>;
174173

175174
type Context = LoaderContext<SwcLoaderOptions>;
176-
export default function swcLoader(this: Context, src: string, srcMap?: string) {
175+
export default function swcLoader(this: Context, src: string) {
177176
const pluginOptions = this.getOptions();
178177
validate(schema, pluginOptions, { name: 'swcLoader' });
179178

180179
const options: Options = {
181180
...pluginOptions,
182181
envName: this.mode,
183182
filename: this.resourcePath,
184-
inputSourceMap:
185-
// some files in node_modules claim to have sourcemaps when they do
186-
// not[0], and SWC has a bug where logs to stderror if it tries to use a
187-
// sourcemap that does not exist[1]. So we disable sourcemaps for
188-
// node_modules. Ideally, we would not disable them, as they *are* useful
189-
// for debugging.
190-
// [0]: https://github.com/trezor/trezor-suite/issues/20298
191-
// [1]: https://github.com/swc-project/swc/issues/9416
192-
this.resourcePath.includes(`${sep}node_modules${sep}`) ? false : srcMap,
183+
inputSourceMap: false,
193184
sourceFileName: this.resourcePath,
194185
sourceMaps: this.sourceMap,
195186
swcrc: false,

development/webpack/webpack.config.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import rtlCss from 'postcss-rtlcss';
1818
import autoprefixer from 'autoprefixer';
1919
import discardFonts from 'postcss-discard-font-face';
2020
import type ReactRefreshPluginType from '@pmmmwh/react-refresh-webpack-plugin';
21+
import {
22+
defineReactCompilerLoaderOption,
23+
reactCompilerLoader,
24+
} from 'react-compiler-webpack';
2125
import tailwindcss from 'tailwindcss';
2226
import { loadBuildTypesConfig } from '../lib/build-type';
2327
import {
@@ -33,7 +37,11 @@ import { transformManifest } from './utils/plugins/ManifestPlugin/helpers';
3337
import { parseArgv, getDryRunMessage } from './utils/cli';
3438
import { getCodeFenceLoader } from './utils/loaders/codeFenceLoader';
3539
import { getSwcLoader } from './utils/loaders/swcLoader';
36-
import { getVariables } from './utils/config';
40+
import {
41+
getVariables,
42+
reactCompilerOptions,
43+
getReactCompilerLogger,
44+
} from './utils/config';
3745
import { ManifestPlugin } from './utils/plugins/ManifestPlugin';
3846
import { getLatestCommit } from './utils/git';
3947

@@ -210,6 +218,17 @@ if (args.progress) {
210218
const { ProgressPlugin } = require('webpack');
211219
plugins.push(new ProgressPlugin());
212220
}
221+
222+
// React Compiler statistics logger plugin
223+
plugins.push({
224+
apply(compiler) {
225+
compiler.hooks.done.tap('ReactCompilerStatsPlugin', () => {
226+
const logger = getReactCompilerLogger();
227+
logger.logSummary();
228+
});
229+
},
230+
} as WebpackPluginInstance);
231+
213232
// #endregion plugins
214233

215234
const swcConfig = { args, browsersListQuery, isDevelopment };
@@ -323,13 +342,24 @@ const config = {
323342
{
324343
test: /\.(?:ts|mts|tsx)$/u,
325344
exclude: NODE_MODULES_RE,
326-
use: [tsxLoader, codeFenceLoader],
345+
use: [tsxLoader],
327346
},
328347
// own javascript, and own javascript with jsx
329348
{
330349
test: /\.(?:js|mjs|jsx)$/u,
331350
exclude: NODE_MODULES_RE,
332-
use: [jsxLoader, codeFenceLoader],
351+
use: [jsxLoader],
352+
},
353+
{
354+
test: /\.(?:js|mjs|jsx|ts|mts|tsx)$/u,
355+
exclude: NODE_MODULES_RE,
356+
use: [
357+
{
358+
loader: reactCompilerLoader,
359+
options: defineReactCompilerLoaderOption(reactCompilerOptions),
360+
},
361+
codeFenceLoader,
362+
],
333363
},
334364
// vendor javascript. We must transform all npm modules to ensure browser
335365
// compatibility.

lavamoat/build-system/policy.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@
291291
"@babel/preset-env>@babel/helper-plugin-utils": true
292292
}
293293
},
294-
"@babel/preset-typescript>@babel/plugin-syntax-jsx": {
294+
"react-compiler-webpack>@babel/plugin-syntax-jsx": {
295295
"packages": {
296296
"@babel/preset-env>@babel/helper-plugin-utils": true
297297
}
@@ -584,7 +584,7 @@
584584
"@babel/preset-env>@babel/plugin-transform-classes>@babel/helper-annotate-as-pure": true,
585585
"@babel/core>@babel/helper-module-transforms>@babel/helper-module-imports": true,
586586
"@babel/preset-env>@babel/helper-plugin-utils": true,
587-
"@babel/preset-typescript>@babel/plugin-syntax-jsx": true
587+
"react-compiler-webpack>@babel/plugin-syntax-jsx": true
588588
}
589589
},
590590
"@babel/preset-react>@babel/plugin-transform-react-pure-annotations": {
@@ -768,7 +768,7 @@
768768
"packages": {
769769
"@babel/preset-env>@babel/helper-plugin-utils": true,
770770
"@babel/preset-env>@babel/helper-validator-option": true,
771-
"@babel/preset-typescript>@babel/plugin-syntax-jsx": true,
771+
"react-compiler-webpack>@babel/plugin-syntax-jsx": true,
772772
"@babel/preset-env>@babel/plugin-transform-modules-commonjs": true,
773773
"@babel/preset-typescript>@babel/plugin-transform-typescript": true
774774
}

lavamoat/webpack/mv2/policy.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4847,6 +4847,14 @@
48474847
"react": true
48484848
}
48494849
},
4850+
"react-compiler-runtime": {
4851+
"globals": {
4852+
"console.error": true
4853+
},
4854+
"packages": {
4855+
"react": true
4856+
}
4857+
},
48504858
"react-devtools-core": {
48514859
"globals": {
48524860
"CSSStyleRule": true,

lavamoat/webpack/mv3/policy.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3372,6 +3372,14 @@
33723372
"react": true
33733373
}
33743374
},
3375+
"react-compiler-runtime": {
3376+
"globals": {
3377+
"console.error": true
3378+
},
3379+
"packages": {
3380+
"react": true
3381+
}
3382+
},
33753383
"react-devtools-core": {
33763384
"globals": {
33773385
"CSSStyleRule": true,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@
682682
"process": "^0.11.10",
683683
"pumpify": "^2.0.1",
684684
"randomcolor": "^0.5.4",
685+
"react-compiler-webpack": "0.2.1",
685686
"react-devtools": "^6.1.5",
686687
"react-devtools-core": "^6.1.5",
687688
"react-syntax-highlighter": "^15.5.0",

ui/components/app/assets/token-list/token-list.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use no memo';
2+
13
import React, { useContext, useEffect, useMemo } from 'react';
24
import { useSelector } from 'react-redux';
35
import { type CaipChainId, type Hex } from '@metamask/utils';
@@ -154,7 +156,7 @@ function TokenList({ onTokenClick, safeChains }: TokenListProps) {
154156
]);
155157

156158
const virtualizer = useVirtualizer({
157-
count: sortedFilteredTokens.length,
159+
count: sortedFilteredTokens?.length ?? 0,
158160
getScrollElement: () => scrollContainerRef?.current || null,
159161
estimateSize: () => ASSET_CELL_HEIGHT,
160162
overscan: 5,

ui/components/app/toast-master/toast-master.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ function SurveyToastMayDelete() {
330330
}
331331

332332
function PrivacyPolicyToast() {
333+
'use no memo';
334+
333335
const t = useI18nContext();
334336

335337
const { showPrivacyPolicyToast, newPrivacyPolicyToastShownDate } =

0 commit comments

Comments
 (0)