Skip to content

fix: add default enable networks state and null guards#40402

Merged
Prithpal-Sooriya merged 8 commits intomainfrom
cursor/enabled-networks-undefined-error-6e98
Feb 27, 2026
Merged

fix: add default enable networks state and null guards#40402
Prithpal-Sooriya merged 8 commits intomainfrom
cursor/enabled-networks-undefined-error-6e98

Conversation

@Prithpal-Sooriya
Copy link
Contributor

@Prithpal-Sooriya Prithpal-Sooriya commented Feb 25, 2026

Description

The redux state we are picking might not exist if accessed before state gets rehydrated.

Added a default state to enabled networks, and also a null guard for where we initially select from this state

Open in GitHub Codespaces

Changelog

CHANGELOG entry: fix: add enable networks null guards

Related issues

Fixes: #35232 https://consensyssoftware.atlassian.net/browse/ASSETS-2021

Manual testing steps

Screenshots/Recordings

Before

After

Pre-merge author checklist

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.

Open in Web Open in Cursor 


Note

Low Risk
Low risk: small selector hardening to avoid crashes when enabledNetworkMap or its eip155 entry is undefined; behavior only changes in uninitialized/rehydration edge cases.

Overview
Prevents selector crashes when Redux state hasn’t rehydrated by defaulting getEnabledNetworks to an empty map and guarding selectAllEnabledNetworkClientIds against a missing eip155 namespace entry.

Written by Cursor Bugbot for commit 499a629. This will update automatically on new commits. Configure here.

The getEnabledNetworks selector returns state.metamask.enabledNetworkMap
which can be undefined if the state hasn't been properly initialized.
Multiple selectors were accessing properties on this potentially undefined
object, causing 'TypeError: Cannot read properties of undefined (reading eip155)'.

This fix adds optional chaining (?.) and nullish coalescing (?? {}) to all
affected selectors to gracefully handle the undefined case:

- getEnabledNetworksByNamespace
- getAllEnabledNetworksForAllNamespaces
- selectEnabledNetworksAsCaipChainIds
- selectNonEvmChainIds
- getEnabledChainIds
- getEnabledNetworkClientIds
- selectAnyEnabledNetworksAreAvailable
- selectFirstUnavailableEvmNetwork
- selectAllEnabledNetworkClientIds

Fixes: METAMASK-XPHD

Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
@cursor
Copy link

cursor bot commented Feb 25, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Feb 25, 2026

Builds ready [c364841]
⚡ Performance Benchmarks (1448 ± 114 ms)
👆 Interaction Benchmarks
ActionMetricMean (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account29923305332
total29923305332
Confirm Txconfirm_tx6061760666068
total6061760666068
Bridge User Actionsbridge_load_page21327221257
bridge_load_asset_picker22243272276
bridge_search_token72320729753
total11576111851246
🔌 Startup Benchmarks
BuildMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
Chrome Browserify Startup Standard HomeuiStartup14481204183511414881633
load121599114759512601351
domContentLoaded120898614699312561344
domInteractive291791182580
firstPaint161671170123214267
backgroundConnect21819746331218244
firstReactRender19133942026
initialActions105114
loadScripts101078712649210571155
setupStore1363351519
numNetworkReqs312291192282
Chrome Browserify Startup Power User HomeuiStartup2492145811017153123054768
load12481052177816912961726
domContentLoaded12321043174015912751635
domInteractive39192493435116
firstPaint247711696268283430
backgroundConnect790262881213463912720
firstReactRender25165692644
initialActions104112
loadScripts1020845151715610681412
setupStore1584281735
numNetworkReqs74381552787133
Chrome Webpack Startup Standard HomeuiStartup8497021121928881025
load73061391887785877
domContentLoaded72460991386781871
domInteractive2715100202383
firstPaint1156435157160214
backgroundConnect28205573242
firstReactRender18124562031
initialActions103112
loadScripts72160791185779869
setupStore1264161223
numNetworkReqs312299202587
Chrome Webpack Startup Power User HomeuiStartup1232917245920412881552
load7456341351111739998
domContentLoaded7346271337111724992
domInteractive39192003137110
firstPaint15565731108176303
backgroundConnect17913686681176277
firstReactRender23183532528
initialActions102011
loadScripts7326251327110722982
setupStore1353451520
numNetworkReqs75371703087145
Firefox Browserify Startup Standard HomeuiStartup16401396286923416602106
load13671159210514314131607
domContentLoaded13661158210114314131606
domInteractive79332875797210
firstPaint------
backgroundConnect7226111211556148
firstReactRender13111911315
initialActions103112
loadScripts13391137207213513831550
setupStore187169251436
numNetworkReqs321996212593
Firefox Browserify Startup Power User HomeuiStartup27781989677872228633285
load15991199549265115582332
domContentLoaded15981199549265115572331
domInteractive14035765123140371
firstPaint------
backgroundConnect3611131292293478950
firstReactRender18146181822
initialActions2010122
loadScripts15631174542564715292295
setupStore1386767173140522
numNetworkReqs752919039100154
Firefox Webpack Startup Standard HomeuiStartup17461452358336417292166
load14801216312132714711668
domContentLoaded14801216312132714711668
domInteractive145311632253132234
firstPaint------
backgroundConnect7124140413763115
firstReactRender15122731624
initialActions104122
loadScripts14421195309029614471589
setupStore247170321768
numNetworkReqs312091182780
Firefox Webpack Startup Power User HomeuiStartup26911969444643428073597
load15381227336330116172013
domContentLoaded15371226336330116172013
domInteractive15133836161145571
firstPaint------
backgroundConnect3971181380314520977
firstReactRender22166892329
initialActions203122
loadScripts14981209330529515571970
setupStore13510924174118580
numNetworkReqs73281823996158
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2202222223
srpButtonToSrpForm9519697
confirmSrpToPwForm2202223
pwFormToMetricsScreen1601616
metricsToWalletReadyScreen1811919
doneButtonToHomeScreen109124212471360
openAccountMenuToAccountListLoaded739825376957695
total886210989688975
Onboarding New WalletcreateWalletToSocialScreen2191220220
srpButtonToPwForm1062107108
createPwToRecoveryScreen8088
skipBackupToMetricsScreen3613637
agreeButtonToOnboardingSuccess1601617
doneButtonToAssetList115311211721298
total153711015551679
Asset DetailsassetClickToPriceChart53126670
total53126670
Solana Asset DetailsassetClickToPriceChart4614648
total4614648
Import Srp HomeloginToHomeScreen19719320362115
openAccountMenuAfterLogin3914040
homeAfterImportWithNewWallet241219824812693
total425812843904390
Send TransactionsopenSendPageFromHome1921922
selectTokenToSendFormLoaded2582939
reviewTransactionToConfirmationPage8528851866
total90820908939
SwapopenSwapPageFromHome1221124124
fetchAndDisplaySwapQuotes45821445754605
total47061247024727
🌐 Dapp Page Load Benchmarks

Current Commit: c364841 | Date: 2/25/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.06s (±40ms) 🟡 | historical mean value: 1.04s ⬆️ (historical data)
  • domContentLoaded-> current mean value: 738ms (±38ms) 🟢 | historical mean value: 728ms ⬆️ (historical data)
  • firstContentfulPaint-> current mean value: 79ms (±10ms) 🟢 | historical mean value: 77ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.06s 40ms 1.03s 1.35s 1.09s 1.35s
domContentLoaded 738ms 38ms 713ms 1.02s 765ms 1.02s
firstPaint 79ms 10ms 68ms 160ms 92ms 160ms
firstContentfulPaint 79ms 10ms 68ms 160ms 92ms 160ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs
  • background: 58 Bytes (0%)
  • ui: 5 Bytes (0%)
  • common: 125 Bytes (0%)

(allEnabledNetworks, defaultNetworkClientIdsByChainId) => {
const chainIds = Object.entries(
allEnabledNetworks[KnownCaipNamespace.Eip155],
allEnabledNetworks?.[KnownCaipNamespace.Eip155] ?? {},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice this is valid.

Per review feedback, moved the null guard to the source selector
(getEnabledNetworks) instead of adding individual guards to each
downstream selector. This is cleaner and ensures all current and
future consumers are automatically protected.

The change: state.metamask.enabledNetworkMap ?? {}

This prevents TypeError when enabledNetworkMap is undefined during
state initialization.

Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
@Prithpal-Sooriya Prithpal-Sooriya changed the title Enabled networks undefined error fix: add enable networks null guards Feb 26, 2026
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
Co-authored-by: Prithpal Sooriya <prithpal.sooriya@gmail.com>
@Prithpal-Sooriya Prithpal-Sooriya marked this pull request as ready for review February 26, 2026 12:33
@github-actions
Copy link
Contributor

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.

bergarces
bergarces previously approved these changes Feb 26, 2026
… in getEnabledNetworks selector

This change centralizes the default value for enabled networks, preventing potential TypeErrors when accessing the state. The selector now returns an empty object if the enabledNetworkMap is undefined, enhancing stability during state initialization.
@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Feb 26, 2026

Builds ready [d741d0e]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account29027730711296307
total29027730711296307
Confirm Txconfirm_tx6037601960621560416062
total6037601960621560416062
Bridge User Actionsbridge_load_page21419324420221244
bridge_load_asset_picker23919231446269314
bridge_search_token71670074116718741
total1215110413479412781347
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup14991258188311715661654
load12631045158010513321425
domContentLoaded12541026157210513261418
domInteractive3117106202786
firstPaint162721236129213269
backgroundConnect22420529016225252
firstReactRender20134462132
initialActions108123
loadScripts1049824136210411231212
setupStore1464071729
numNetworkReqs312295202285
Power User HomeuiStartup2877146510195189137326826
load12421041177114412891556
domContentLoaded12251029165613612641515
domInteractive37201602736111
firstPaint202761664169251339
backgroundConnect10762668689148614103079
firstReactRender24165562638
initialActions104112
loadScripts1004828144013110251279
setupStore1563861626
numNetworkReqs80431452295121
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2182172201219220
srpButtonToSrpForm96949829798
confirmSrpToPwForm23222412324
pwFormToMetricsScreen16161601616
metricsToWalletReadyScreen17171701717
doneButtonToHomeScreen83879689341893893
openAccountMenuToAccountListLoaded75297230785620876327856
total8796863388939488768893
Onboarding New WalletcreateWalletToSocialScreen2202192211221221
srpButtonToPwForm1071031103110110
createPwToRecoveryScreen989099
skipBackupToMetricsScreen36343713637
agreeButtonToOnboardingSuccess17171701717
doneButtonToAssetList1019677143830513301438
total14211068182531717811825
Asset DetailsassetClickToPriceChart40374324143
total40374324143
Solana Asset DetailsassetClickToPriceChart47464814848
total47464814848
Import Srp HomeloginToHomeScreen2017200520381520382038
openAccountMenuAfterLogin43424314343
homeAfterImportWithNewWallet2138203322077322062207
total43344113475024244654750
Send TransactionsopenSendPageFromHome271845123845
selectTokenToSendFormLoaded22203052030
reviewTransactionToConfirmationPage8708578849871884
total9439359485946948
SwapopenSwapPageFromHome1099113214115132
fetchAndDisplaySwapQuotes4639457547416146724741
total4748469048415547804841
🌐 Dapp Page Load Benchmarks

Current Commit: d741d0e | Date: 2/26/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.07s (±43ms) 🟡 | historical mean value: 1.04s ⬆️ (historical data)
  • domContentLoaded-> current mean value: 757ms (±63ms) 🟢 | historical mean value: 734ms ⬆️ (historical data)
  • firstContentfulPaint-> current mean value: 96ms (±131ms) 🟢 | historical mean value: 82ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.07s 43ms 1.05s 1.41s 1.10s 1.41s
domContentLoaded 757ms 63ms 726ms 1.33s 772ms 1.33s
firstPaint 96ms 131ms 64ms 1.40s 92ms 1.40s
firstContentfulPaint 96ms 131ms 64ms 1.40s 92ms 1.40s
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs
  • background: 58 Bytes (0%)
  • ui: 5 Bytes (0%)
  • common: 32 Bytes (0%)

@Prithpal-Sooriya Prithpal-Sooriya added this pull request to the merge queue Feb 27, 2026
@Prithpal-Sooriya Prithpal-Sooriya changed the title fix: add enable networks null guards fix: add default enable networks state and null guards Feb 27, 2026
@Prithpal-Sooriya Prithpal-Sooriya removed this pull request from the merge queue due to a manual request Feb 27, 2026
@Prithpal-Sooriya Prithpal-Sooriya added this pull request to the merge queue Feb 27, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 27, 2026
@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Feb 27, 2026

Builds ready [cde6708]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account28126629613294296
total28126629613294296
Confirm Txconfirm_tx6028600860481460376048
total6028600860481460376048
Bridge User Actionsbridge_load_page22820024818237248
bridge_load_asset_picker24021827220242272
bridge_search_token73670775117749751
total1208119212181112181218
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup14661238187011515211661
load12471048161310213111407
domContentLoaded12381027160610312841399
domInteractive271795192485
firstPaint1626839278232273
backgroundConnect22019841128218257
firstReactRender19124051929
initialActions108123
loadScripts1038826140310310861206
setupStore1463671631
numNetworkReqs322290193181
Power User HomeuiStartup17741388220614418332073
load11771055187814611781562
domContentLoaded11641047186814411621528
domInteractive3821175263691
firstPaint1808043884241320
backgroundConnect29726643023307331
firstReactRender23156072441
initialActions104112
loadScripts94783116191419451297
setupStore1674271729
numNetworkReqs59391482459130
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2212202221221222
srpButtonToSrpForm98989809898
confirmSrpToPwForm24232402424
pwFormToMetricsScreen16151711717
metricsToWalletReadyScreen18172121921
doneButtonToHomeScreen1029612138728212501387
openAccountMenuToAccountListLoaded75467052808736977178087
total89568682913215790749132
Onboarding New WalletcreateWalletToSocialScreen2212192231222223
srpButtonToPwForm1101061164111116
createPwToRecoveryScreen99100910
skipBackupToMetricsScreen36363703737
agreeButtonToOnboardingSuccess17161811718
doneButtonToAssetList61453169659629696
total100691910866010221086
Asset DetailsassetClickToPriceChart43414514545
total43414514545
Solana Asset DetailsassetClickToPriceChart47464814748
total47464814748
Import Srp HomeloginToHomeScreen1890186219403018881940
openAccountMenuAfterLogin44405044750
homeAfterImportWithNewWallet22342048249818724182498
total42924031462622044104626
Send TransactionsopenSendPageFromHome24173483434
selectTokenToSendFormLoaded19172122021
reviewTransactionToConfirmationPage8518488543854854
total90288592313906923
SwapopenSwapPageFromHome1121031258115125
fetchAndDisplaySwapQuotes4626456947577746044757
total4727463348729047294872
🌐 Dapp Page Load Benchmarks

Current Commit: cde6708 | Date: 2/27/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.06s (±45ms) 🟡 | historical mean value: 1.04s ⬆️ (historical data)
  • domContentLoaded-> current mean value: 748ms (±66ms) 🟢 | historical mean value: 733ms ⬆️ (historical data)
  • firstContentfulPaint-> current mean value: 84ms (±43ms) 🟢 | historical mean value: 84ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.06s 45ms 1.03s 1.39s 1.09s 1.39s
domContentLoaded 748ms 66ms 725ms 1.35s 769ms 1.35s
firstPaint 84ms 43ms 60ms 512ms 88ms 512ms
firstContentfulPaint 84ms 43ms 60ms 512ms 88ms 512ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs
  • background: 58 Bytes (0%)
  • ui: 5 Bytes (0%)
  • common: 32 Bytes (0%)

@sonarqubecloud
Copy link

@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Feb 27, 2026

Builds ready [499a629]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account30527336636327366
total30527336636327366
Confirm Txconfirm_tx609160856095460946095
total609160856095460946095
Bridge User Actionsbridge_load_page2592582611261261
bridge_load_asset_picker22815331968294319
bridge_search_token73371476120753761
total1217112513137612761313
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup13921164172410714261627
load117099613989111991366
domContentLoaded116498013949111941358
domInteractive271693182476
firstPaint1406635967195255
backgroundConnect20519025611207227
firstReactRender18133542027
initialActions107125
loadScripts97479411969110011164
setupStore1262941419
numNetworkReqs322287193182
Power User HomeuiStartup17311396220515618002019
load11481030171313811501538
domContentLoaded11331026165313111321494
domInteractive3520191233558
firstPaint198781608210240300
backgroundConnect29026135820296327
firstReactRender24165972642
initialActions108124
loadScripts92481914381289151288
setupStore1683561827
numNetworkReqs60391532562130
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2212202210221221
srpButtonToSrpForm94919629696
confirmSrpToPwForm21212202222
pwFormToMetricsScreen15151501515
metricsToWalletReadyScreen16161601616
doneButtonToHomeScreen1124611150333013661503
openAccountMenuToAccountListLoaded74067030788731876637887
total8878886289102289108910
Onboarding New WalletcreateWalletToSocialScreen2182172191218219
srpButtonToPwForm1061041071107107
createPwToRecoveryScreen888088
skipBackupToMetricsScreen35343613636
agreeButtonToOnboardingSuccess16161601616
doneButtonToAssetList904579139736913111397
total1286961178036916931780
Asset DetailsassetClickToPriceChart573479177279
total573479177279
Solana Asset DetailsassetClickToPriceChart47454814848
total47454814848
Import Srp HomeloginToHomeScreen2027193121718820582171
openAccountMenuAfterLogin40324754547
homeAfterImportWithNewWallet22662090243012323052430
total42984052453418143894534
Send TransactionsopenSendPageFromHome18181901819
selectTokenToSendFormLoaded21182422324
reviewTransactionToConfirmationPage8528498563854856
total8968919045897904
SwapopenSwapPageFromHome1036413424119134
fetchAndDisplaySwapQuotes52664585623477461936234
total53694690632877763126328
🌐 Dapp Page Load Benchmarks

Current Commit: 499a629 | Date: 2/27/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.06s (±40ms) 🟡 | historical mean value: 1.04s ⬆️ (historical data)
  • domContentLoaded-> current mean value: 743ms (±38ms) 🟢 | historical mean value: 732ms ⬆️ (historical data)
  • firstContentfulPaint-> current mean value: 83ms (±13ms) 🟢 | historical mean value: 83ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.06s 40ms 1.02s 1.36s 1.08s 1.36s
domContentLoaded 743ms 38ms 717ms 1.03s 769ms 1.03s
firstPaint 83ms 13ms 64ms 200ms 92ms 200ms
firstContentfulPaint 83ms 13ms 64ms 200ms 92ms 200ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs
  • background: 58 Bytes (0%)
  • ui: 5 Bytes (0%)
  • common: 32 Bytes (0%)

@Prithpal-Sooriya Prithpal-Sooriya added this pull request to the merge queue Feb 27, 2026
Merged via the queue into main with commit 6084448 Feb 27, 2026
338 of 340 checks passed
@Prithpal-Sooriya Prithpal-Sooriya deleted the cursor/enabled-networks-undefined-error-6e98 branch February 27, 2026 16:21
@github-actions github-actions bot locked and limited conversation to collaborators Feb 27, 2026
@metamaskbot metamaskbot added the release-13.22.0 Issue or pull request that will be included in release 13.22.0 label Feb 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-13.22.0 Issue or pull request that will be included in release 13.22.0 size-XS team-assets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Sentry] TypeError: Cannot read properties of undefined (reading 'eip155')

5 participants