Repository navigation
refactor: configure network test timing in extension - #47090
davidmurdoch wants to merge 4 commits into
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Builds ready [848c2f5]
⚡ Performance Benchmarks (Total: 🟢 8 pass · 🟡 3 warn · 🔴 2 fail)
Bundle Size Diffs
|
Builds ready [00d8835]
⚡ Performance Benchmarks (Total: 🟢 9 pass · 🟡 2 warn · 🔴 2 fail)
Bundle Size Diffs
|
|
## **Description** Simplify the configuration added by the SWC 1.16.2 bump in #46950 while keeping the environment substitutions explicit. SWC's transform API selects TSX parsing from the filename, so `.ts`, `.mts` and `.tsx` can share one TypeScript loader, including React Refresh. The environment-validation loader uses the parse API and still explicitly enables TSX for `.tsx` files. Only the `.js`/`.mjs` dependency loader substitutes `IN_TEST` and `NODE_ENV`. The current network-controller resolves to its ESM build, and the traced production Chrome test graph contains no CJS-loader inputs reading either flag. The CJS loader therefore keeps an empty environment map. The regression tests warm SWC with first-party values and then verify the vendor substitutions, including that other build values are not inherited. Inlining `NODE_ENV` before LavaMoat analysis removes the runtime permissions introduced by the parent branch. The regenerated MV2/MV3 policies remove 35 `process.env.NODE_ENV` grants per build variant without changing other permissions. The `IN_TEST` workaround stays in place for this upgrade. A TODO links the Core and Extension follow-ups that will replace it with explicit polling configuration and E2E gas-estimation mocks. Validation: - `yarn lint:changed:fix` - 64 focused webpack loader, environment-validation and configuration tests - `yarn lint:tsc` - JSON formatting checks for the policy files - `yarn lavamoat:auto` across all eight production policy variants ## **Changelog** CHANGELOG entry: null ## **Related issues** Stacked on #46950; targets `bump/swc-core-1.16.2`. Follow-up cleanup tracked by the TODO: MetaMask/core#10831 and #47090. ## **Manual testing steps** 1. Load the Chrome test build, unlock a test wallet and select a custom local network. 2. Send ETH. Verify the confirmation displays a gas fee and the balance updates after confirmation. 3. Open the wallet UI in a development watch build, change text in a TSX component and verify React Refresh updates it without a parsing error. 4. Load the Firefox build and verify the wallet opens and a transaction confirmation loads. <!-- ## **Screenshots/Recordings** No user interface changes. ### **Before** ### **After** --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR. - [ ] I confirm that this PR addresses all acceptance criteria and includes the necessary testing evidence.
## **Description** Bumps `@swc/core` from **1.13.3 → 1.16.2** to fix non-deterministic Firefox builds (one of the [four root causes](#46845) of AMO rebuild mismatches in `runtime.js`). Background on the mechanism: [comment on #46845](#46845 (comment)). Extracted from #46845. Webpack wiring was later simplified in #47092. ### Problem SWC cached parsed `process.env` substitution values **with stale source positions** from whichever file was compiled first. That corrupted source maps, changed module hashes, and made rebuilds non-byte-identical. The cache was also keyed incorrectly, so first-party env substitutions could leak into `node_modules`. Fixed upstream in swc-project/swc#12129 and swc-project/swc#12166 (shipped in **1.16.2**). ### What this PR changes 1. **Bump** `@swc/core` to 1.16.2. 2. **TypeScript loader:** `tsx: false` by default. Transform still enables TSX from `.tsx` filenames, so `.ts` / `.mts` / `.tsx` share one loader. 3. **`envValidationLoader`:** parse API does not enable TSX from the filename, so it still sets `tsx` only for `.tsx` (avoids misparsing generics in `.ts` / `.mts`). 4. **Vendor ESM env:** explicitly inline `IN_TEST` and `NODE_ENV` only. `IN_TEST` used to leak in via the bad cache. `@metamask/network-controller` needs it for the 1s test block-tracker interval. Temporary until [core#10831](MetaMask/core#10831) and [#47090](#47090). CJS vendors keep an empty env map. ## **Changelog** CHANGELOG entry: null ## **Related issues** Related: [INFRA-3920](https://consensyssoftware.atlassian.net/browse/INFRA-3920) ## **Manual testing steps** 1. Compile webpack tooling if needed: `yarn webpack:tsc` 2. Build Firefox production: `yarn webpack:lavamoat:build:mv2 --env production` 3. Load `dist/firefox` in Firefox (`about:debugging`), unlock or onboard, confirm the UI works with no extension console errors. 4. Run the webpack unit tests that cover this change: `yarn test:unit development/webpack/test/webpack.config.test.ts development/webpack/test/loaders.envValidationLoader.test.ts` 5. Start a Chrome watch build: `yarn start` 6. Edit a `.tsx` file and confirm React Refresh updates without a parse error. <!-- ## **Screenshots/Recordings** ### **Before** ### **After** --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: David Murdoch <187813+davidmurdoch@users.noreply.github.com>
Builds ready [51d9a42]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 3 warn · 🔴 3 fail)
Bundle Size Diffs
|
|



Description
Consume the proposed Core API from MetaMask/core#10831 to keep network test timing in Extension.
The wallet initialization options select one-second polling for custom networks when Extension's own
IN_TESTflag is enabled. Infura and production clients keep Core's default polling interval. Core no longer needs to read that flag.Gas-estimation latency belongs in the E2E RPC mocks. Add an opt-in mock that holds
eth_estimateGasuntil the test releases it, while forwarding other RPC methods to the local node. The existing gas-defaults test now uses that mock explicitly.Draft dependency: This PR intentionally assumes
@metamask/network-controllerand@metamask/walletalready expose the API proposed in the Core PR. Package versions, the lockfile and LavaMoat policies are unchanged. Before merging, release and install those packages, regenerate policies, and run the affected browser E2E suite.Validation:
yarn lint:changed:fixpassed.dvid.me. The original test from main also requests that host locally. The RPC mock uses the already approvedcustomnetwork.testhost, with no privacy-snapshot changes.Changelog
CHANGELOG entry: null
Related issues
Depends on MetaMask/core#10831.
Manual testing steps
After installing the updated Core packages:
Pre-merge author checklist
Pre-merge reviewer checklist