Skip to content

fix: use single PersistenceManager to avoid undesired cascade mechanisms#40499

Open
gauthierpetetin wants to merge 40 commits intomainfrom
fix/single-persistence-manager-instance
Open

fix: use single PersistenceManager to avoid undesired cascade mechanisms#40499
gauthierpetetin wants to merge 40 commits intomainfrom
fix/single-persistence-manager-instance

Conversation

@gauthierpetetin
Copy link
Contributor

@gauthierpetetin gauthierpetetin commented Feb 27, 2026

Description

The purpose of this PR is to use a single PersistenceManager instance, while we previously had two:

  1. One in setup-initial-state-hooks.js (used by Sentry’s state hooks)
  2. One in background.js (used by the rest of the app)

Why is it inconvenient to have 2 PersistenceManager instances?

In some cases, it can lead to undesired cascade mechanisms:

  • We try to read the state while initializing the app
  • The storage read operation fails with background.js' PersistenceManager instance
  • We want to send the error to Sentry
  • Before sending the error to Sentry, we try to check user's consent by reading the state (call to getMetaMetricsEnabled())
  • The storage read operation fails with setup-initial-state-hooks.js' PersistenceManager instance
  • Both issues have different stack traces, leading to duplicate issues in Sentry

What solution do we suggest in this PR?

The suggested solution is to create PersistenceManager instance in 'setup-initial-state-hooks.js' and export it so that 'background.js' can use it as well.

Open in GitHub Codespaces

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

  1. None, Extension should work as it usually does.

Screenshots/Recordings

NA

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.

Note

Medium Risk
Changes how the extension’s persistent storage layer is instantiated and shared during startup, which can affect initialization and error-reporting flows if misconfigured. Adds new context-detection logic for fixture stores that could impact test and MV2/MV3 behavior.

Overview
Uses a single exported persistenceManager from setup-initial-state-hooks.js and reuses it in background.js, removing the separate background-created PersistenceManager to avoid duplicate/cascading storage read failures during early Sentry/metrics checks.

Updates setup-initial-state-hooks.js to create the test FixtureExtensionStore with context-aware initialize behavior (background vs UI via globalThis.self.location.href) and adds a dedicated Jest test suite covering context detection plus the stateHooks wiring (getPersistedState, getBackupState, getSentryState).

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

Keep sentryLocalStore as fallback for pre-init and UI. Add getPersistenceManager()
that returns stateHooks._persistenceManager ?? sentryLocalStore. Register
background's persistenceManager on stateHooks so hooks use it after init.
Prevents get-failed cascade by sharing #dataRetrievalFailing across app and Sentry.

Made-with: Cursor
@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.

@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Feb 27, 2026

Builds ready [e35c6ae]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account2652622683267268
total2652622683267268
Confirm Txconfirm_tx6065602661102960756110
total6065602661102960756110
Bridge User Actionsbridge_load_page22721624912231249
bridge_load_asset_picker2052042071207207
bridge_search_token7037027030703703
total1139111311642111641164
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup14051170196511414451600
load1182986166710012211364
domContentLoaded1174982166110012171350
domInteractive281790172575
firstPaint1427139976207280
backgroundConnect20719130616208233
firstReactRender19124042127
initialActions104123
loadScripts985782146710010271156
setupStore1374061624
numNetworkReqs312295202286
Power User HomeuiStartup206014129035105819543858
load11971047169014312191583
domContentLoaded11821036168213912091540
domInteractive3719164223867
firstPaint1727836878242308
backgroundConnect47426748766593211394
firstReactRender24155882643
initialActions104112
loadScripts96483614611349761320
setupStore1665171831
numNetworkReqs63381552568114
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2202192200220220
srpButtonToSrpForm94949409494
confirmSrpToPwForm22212202222
pwFormToMetricsScreen16151601616
metricsToWalletReadyScreen16161701717
doneButtonToHomeScreen844592126926310301269
openAccountMenuToAccountListLoaded72606856785542176747855
total84717829907452589099074
Onboarding New WalletcreateWalletToSocialScreen2212182232223223
srpButtonToPwForm1061061060106106
createPwToRecoveryScreen889089
skipBackupToMetricsScreen35343613436
agreeButtonToOnboardingSuccess16151811718
doneButtonToAssetList1033593145934113171459
total1421979184634117031846
Asset DetailsassetClickToPriceChart42374854548
total42374854548
Solana Asset DetailsassetClickToPriceChart41265095050
total41265095050
Import Srp HomeloginToHomeScreen19491805209612120382096
openAccountMenuAfterLogin46425034850
homeAfterImportWithNewWallet23642176257015524802570
total44904027504238247145042
Send TransactionsopenSendPageFromHome281843124143
selectTokenToSendFormLoaded21202212122
reviewTransactionToConfirmationPage944848107610610711076
total996898113511311341135
SwapopenSwapPageFromHome1065916136118161
fetchAndDisplaySwapQuotes52914574628578462126285
total53974647640281063726402
🌐 Dapp Page Load Benchmarks

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

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.03s (±50ms) 🟡 | historical mean value: 1.04s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 726ms (±42ms) 🟢 | historical mean value: 729ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 79ms (±13ms) 🟢 | historical mean value: 82ms ⬇️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.03s 50ms 1.01s 1.45s 1.06s 1.45s
domContentLoaded 726ms 42ms 698ms 1.05s 748ms 1.05s
firstPaint 79ms 13ms 64ms 196ms 88ms 196ms
firstContentfulPaint 79ms 13ms 64ms 196ms 88ms 196ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 104 Bytes (0%)
  • ui: -15.35 KiB (-0.18%)
  • common: -561 Bytes (0%)

@gauthierpetetin gauthierpetetin marked this pull request as ready for review March 2, 2026 06:12
@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Mar 2, 2026

Builds ready [38e8ec1]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account32027740649340406
total32027740649340406
Confirm Txconfirm_tx611161006121961216121
total611161006121961216121
Bridge User Actionsbridge_load_page24221726517256265
bridge_load_asset_picker24218334156262341
bridge_search_token72270974011723740
total1219114413226612501322
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup1433120616869714771617
load120499814439112471382
domContentLoaded119699214119012431367
domInteractive3016118222695
firstPaint164691262136216311
backgroundConnect21719627116223248
firstReactRender19123452129
initialActions1010224
loadScripts99780312189010361172
setupStore1363361525
numNetworkReqs312294202285
Power User HomeuiStartup17431387224814417832051
load11601014183914911471527
domContentLoaded11461006173414411371518
domInteractive3820192293787
firstPaint1847655391253328
backgroundConnect29325839324305333
firstReactRender23155072340
initialActions106112
loadScripts93381115181459221310
setupStore1575271627
numNetworkReqs59401522555129
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2192192190219219
srpButtonToSrpForm93919519495
confirmSrpToPwForm22212202222
pwFormToMetricsScreen16151601616
metricsToWalletReadyScreen17161811718
doneButtonToHomeScreen65760381088609810
openAccountMenuToAccountListLoaded76527244785224878457852
total881788108821588218821
Onboarding New WalletcreateWalletToSocialScreen2222192252223225
srpButtonToPwForm1091071112109111
createPwToRecoveryScreen989099
skipBackupToMetricsScreen36363703637
agreeButtonToOnboardingSuccess16161701717
doneButtonToAssetList943600143434012441434
total1338997182633516321826
Asset DetailsassetClickToPriceChart493679165479
total493679165479
Solana Asset DetailsassetClickToPriceChart51485535255
total51485535255
Import Srp HomeloginToHomeScreen1942187620235819692023
openAccountMenuAfterLogin44444514545
homeAfterImportWithNewWallet23702159271522025452715
total42694081448814542634488
Send TransactionsopenSendPageFromHome33224393943
selectTokenToSendFormLoaded21202212122
reviewTransactionToConfirmationPage8548488626861862
total9078939199913919
SwapopenSwapPageFromHome1199616124128161
fetchAndDisplaySwapQuotes53094575623975962316239
total54284736634374763396343
🌐 Dapp Page Load Benchmarks

Current Commit: 38e8ec1 | Date: 3/2/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 973ms (±43ms) 🟢 | historical mean value: 1.05s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 684ms (±41ms) 🟢 | historical mean value: 739ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 77ms (±12ms) 🟢 | historical mean value: 83ms ⬇️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 973ms 43ms 944ms 1.33s 1.00s 1.33s
domContentLoaded 684ms 41ms 661ms 1.02s 714ms 1.02s
firstPaint 77ms 12ms 64ms 188ms 84ms 188ms
firstContentfulPaint 77ms 12ms 64ms 188ms 84ms 188ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs
  • background: 104 Bytes (0%)
  • ui: 5 Bytes (0%)
  • common: 95 Bytes (0%)

@gauthierpetetin gauthierpetetin marked this pull request as draft March 2, 2026 12:10
@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Mar 2, 2026

Builds ready [fe5f3c4]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account29527331214309312
total29527331214309312
Confirm Txconfirm_tx6071604860972060836097
total6071604860972060836097
Bridge User Actionsbridge_load_page29020833348331333
bridge_load_asset_picker22019824317228243
bridge_search_token7457387515749751
total1292126213252613081325
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup14841253175010815521676
load12451046147910213101414
domContentLoaded12361019147110013031401
domInteractive291897182680
firstPaint176731215133234314
backgroundConnect22120027617227264
firstReactRender20124562234
initialActions105124
loadScripts1033813126610010941202
setupStore1473661727
numNetworkReqs312290192584
Power User HomeuiStartup220514385809102421215207
load11941064175013312071530
domContentLoaded11791060173713011941499
domInteractive3721153243587
firstPaint1778246384242325
backgroundConnect54426332556543832261
firstReactRender26175482945
initialActions105113
loadScripts96184215181259751255
setupStore1765191937
numNetworkReqs68341432376115
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2212202231221223
srpButtonToSrpForm93919519395
confirmSrpToPwForm22212202222
pwFormToMetricsScreen15151601516
metricsToWalletReadyScreen16151701617
doneButtonToHomeScreen910642122826612261228
openAccountMenuToAccountListLoaded73956818805442276518054
total882188088831988318831
Onboarding New WalletcreateWalletToSocialScreen2192192200220220
srpButtonToPwForm1071051092108109
createPwToRecoveryScreen888088
skipBackupToMetricsScreen37363703737
agreeButtonToOnboardingSuccess16161701617
doneButtonToAssetList801552116228011241162
total1195953154727415121547
Asset DetailsassetClickToPriceChart63351112767111
total63351112767111
Solana Asset DetailsassetClickToPriceChart48475015050
total48475015050
Import Srp HomeloginToHomeScreen20871922238117621942381
openAccountMenuAfterLogin44394834548
homeAfterImportWithNewWallet23372204252712224222527
total44004244451110144614511
Send TransactionsopenSendPageFromHome36353813638
selectTokenToSendFormLoaded19192111921
reviewTransactionToConfirmationPage8588488656862865
total9129039196916919
SwapopenSwapPageFromHome1311271364136136
fetchAndDisplaySwapQuotes461446044625946254625
total4763469548404947874840
🌐 Dapp Page Load Benchmarks

Current Commit: fe5f3c4 | Date: 3/2/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 980ms (±42ms) 🟢 | historical mean value: 1.05s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 685ms (±36ms) 🟢 | historical mean value: 737ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 76ms (±12ms) 🟢 | historical mean value: 82ms ⬇️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 980ms 42ms 954ms 1.26s 1.02s 1.26s
domContentLoaded 685ms 36ms 666ms 950ms 697ms 950ms
firstPaint 76ms 12ms 64ms 176ms 88ms 176ms
firstContentfulPaint 76ms 12ms 64ms 176ms 88ms 176ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs
  • background: 104 Bytes (0%)
  • ui: 5 Bytes (0%)
  • common: 95 Bytes (0%)

- setup-initial-state-hooks: add isBackgroundContext(), create one
  PersistenceManager per context with FixtureExtensionStore(initialize:
  isBackground); expose via stateHooks.persistenceManager
- background: use stateHooks.persistenceManager instead of creating
  a second instance; remove unused ExtensionStore/FixtureExtensionStore
  and PersistenceManager imports
- getSentryState: use globalThis.navigator for service worker safety

Made-with: Cursor
@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Mar 2, 2026

Builds ready [2578d11]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
🧭 User Journey Benchmarks

⚠️ Missing data: chrome/browserify/userJourneyOnboardingImport

🌐 Dapp Page Load Benchmarks

Current Commit: 2578d11 | Date: 3/2/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.05s (±41ms) 🟡 | historical mean value: 1.05s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 736ms (±39ms) 🟢 | historical mean value: 740ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 82ms (±10ms) 🟢 | historical mean value: 82ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.05s 41ms 1.02s 1.35s 1.07s 1.35s
domContentLoaded 736ms 39ms 713ms 1.03s 758ms 1.03s
firstPaint 82ms 10ms 68ms 164ms 96ms 164ms
firstContentfulPaint 82ms 10ms 68ms 164ms 96ms 164ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs
  • background: -122 Bytes (0%)
  • ui: 5 Bytes (0%)
  • common: 323 Bytes (0%)

Restore window.navigator.userAgent; the globalThis.navigator change
was not part of the single PersistenceManager refactor.

Made-with: Cursor
Export persistenceManager from setup-initial-state-hooks and import
it in background.js; only consumer is background.js which already
imports this module. Keeps state hooks on globalThis.stateHooks for
Sentry and other callers that don't import this module.

Made-with: Cursor
- MV3: detect service worker by undefined window or ServiceWorkerGlobalScope
- MV2: detect background page by URL containing 'background' (e.g. background.html)
- Remove MV3 Firefox reference (not applicable)
- Logic verified in Chrome MV3 (SW + UI) and Firefox MV2 (background + UI)

Made-with: Cursor
@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Mar 6, 2026

Builds ready [ad592e3]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account2662622734264273
total2662622734264273
Confirm Txconfirm_tx603560316038360376038
total603560316038360376038
Bridge User Actionsbridge_load_page25421228026279280
bridge_load_asset_picker17213321328192213
bridge_search_token71970274417735744
total1146107212366612071236
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup1346111915659913981507
load113192013359211771300
domContentLoaded112391513229011721274
domInteractive271798182476
firstPaint188611178179203324
backgroundConnect19617823612204221
firstReactRender19114462030
initialActions107124
loadScripts9447431132889991099
setupStore1363461625
numNetworkReqs3122100212289
Power User HomeuiStartup19461581241514720282175
load11461019179316111361627
domContentLoaded11291007178615411141584
domInteractive3719223283588
firstPaint220651666195248426
backgroundConnect30826042635318379
firstReactRender24165172641
initialActions104112
loadScripts91180015611478961336
setupStore1462941721
numNetworkReqs69362064655171
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2202202211221221
srpButtonToSrpForm95929729597
confirmSrpToPwForm22212202222
pwFormToMetricsScreen15151601616
metricsToWalletReadyScreen16151701617
doneButtonToHomeScreen64960069536670695
openAccountMenuToAccountListLoaded2937291829581429362958
total4019392741047241034104
Onboarding New WalletcreateWalletToSocialScreen2212182252223225
srpButtonToPwForm1101091111111111
createPwToRecoveryScreen989099
skipBackupToMetricsScreen36353603636
agreeButtonToOnboardingSuccess17171701717
doneButtonToAssetList52147961555496615
total9148761007548881007
Asset DetailsassetClickToPriceChart13511716217143162
total13511716217143162
Solana Asset DetailsassetClickToPriceChart87849138991
total87849138991
Import Srp HomeloginToHomeScreen20721958224010721332240
openAccountMenuAfterLogin49376395263
homeAfterImportWithNewWallet2433232625849124862584
total45544338488819946564888
Send TransactionsopenSendPageFromHome22173152631
selectTokenToSendFormLoaded20182522125
reviewTransactionToConfirmationPage8478458491848849
total8898838944893894
SwapopenSwapPageFromHome45335695556
fetchAndDisplaySwapQuotes268626832688226872688
total2735271927591527432759
🌐 Dapp Page Load Benchmarks

Current Commit: ad592e3 | Date: 3/6/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.04s (±40ms) 🟡 | historical mean value: 1.05s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 733ms (±38ms) 🟢 | historical mean value: 741ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 80ms (±11ms) 🟢 | historical mean value: 82ms ⬇️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.04s 40ms 1.02s 1.35s 1.08s 1.35s
domContentLoaded 733ms 38ms 707ms 1.03s 763ms 1.03s
firstPaint 80ms 11ms 64ms 168ms 88ms 168ms
firstContentfulPaint 80ms 11ms 64ms 168ms 88ms 168ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 398 Bytes (0.01%)
  • ui: 5 Bytes (0%)
  • common: 695 Bytes (0.01%)

Define getEnvironmentTypeForHooks locally in setup-initial-state-hooks.js,
using shared getEnvironmentType, and remove app/scripts/lib/get-environment-type.ts.

Made-with: Cursor
@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Mar 6, 2026

Builds ready [656a270]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account412277702164489702
total412277702164489702
Confirm Txconfirm_tx6144606462366561846236
total6144606462366561846236
Bridge User Actionsbridge_load_page2472432493249249
bridge_load_asset_picker18314423436214234
bridge_search_token73670277827752778
total1169109412555912021255
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup14481193196112914951682
load12151017166910912621399
domContentLoaded12081012162210612541392
domInteractive2815105202577
firstPaint1767240383234293
backgroundConnect21519731417215246
firstReactRender19124761933
initialActions105114
loadScripts1011810141710610551202
setupStore1374161625
numNetworkReqs312295202286
Power User HomeuiStartup2478173111570117123414626
load12491070202118312571710
domContentLoaded12351063198218112461694
domInteractive39201262437103
firstPaint197811754186239426
backgroundConnect54626988799583401851
firstReactRender25175672838
initialActions1011113
loadScripts1008847177217310181436
setupStore1876291932
numNetworkReqs79352204690170
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2192172201218220
srpButtonToSrpForm100951075102107
confirmSrpToPwForm22222302323
pwFormToMetricsScreen16151701617
metricsToWalletReadyScreen17171701717
doneButtonToHomeScreen69661676553743765
openAccountMenuToAccountListLoaded2930290929501529442950
total4005399540211140214021
Onboarding New WalletcreateWalletToSocialScreen2182182190219219
srpButtonToPwForm1171081319123131
createPwToRecoveryScreen99100910
skipBackupToMetricsScreen36353713737
agreeButtonToOnboardingSuccess17161711717
doneButtonToAssetList53648863459524634
total9318841022559261022
Asset DetailsassetClickToPriceChart18512523737207237
total18512523737207237
Solana Asset DetailsassetClickToPriceChart88839349293
total88839349293
Import Srp HomeloginToHomeScreen1952191619822319551982
openAccountMenuAfterLogin39304564345
homeAfterImportWithNewWallet24732325266612825462666
total45304337487220746574872
Send TransactionsopenSendPageFromHome24183473034
selectTokenToSendFormLoaded19162022020
reviewTransactionToConfirmationPage9058461058898691058
total9458831095879091095
SwapopenSwapPageFromHome44365264952
fetchAndDisplaySwapQuotes268426832684126842684
total272827202736727362736
🌐 Dapp Page Load Benchmarks

Current Commit: 656a270 | Date: 3/6/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.07s (±41ms) 🟡 | historical mean value: 1.05s ⬆️ (historical data)
  • domContentLoaded-> current mean value: 750ms (±38ms) 🟢 | historical mean value: 740ms ⬆️ (historical data)
  • firstContentfulPaint-> current mean value: 84ms (±13ms) 🟢 | historical mean value: 81ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.07s 41ms 1.02s 1.36s 1.12s 1.36s
domContentLoaded 750ms 38ms 715ms 1.02s 798ms 1.02s
firstPaint 84ms 13ms 72ms 196ms 96ms 196ms
firstContentfulPaint 84ms 13ms 72ms 196ms 96ms 196ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs
  • background: 398 Bytes (0.01%)
  • ui: 5 Bytes (0%)
  • common: 463 Bytes (0%)

@gauthierpetetin gauthierpetetin changed the title fix: use single PersistenceManager for hooks once background is ready fix: use single PersistenceManager Mar 6, 2026
@gauthierpetetin gauthierpetetin changed the title fix: use single PersistenceManager fix: use single PersistenceManager to avoid undesired cascade mechanisms Mar 6, 2026
@gauthierpetetin gauthierpetetin marked this pull request as draft March 16, 2026 15:32
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Mar 16, 2026

Builds ready [a073850]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account29727132118302321
total29727132118302321
Confirm Txconfirm_tx6060603260812060766081
total6060603260812060766081
Bridge User Actionsbridge_load_page24218928836270288
bridge_load_asset_picker2572522604260260
bridge_search_token7617617620762762
total1259123512912012671291
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup15291331217711715691717
load12661068172510213111443
domContentLoaded12591061172010213051434
domInteractive3318156262795
firstPaint180751412149220323
backgroundConnect22720428213229250
firstReactRender21124662235
initialActions108124
loadScripts1048847149610110921222
setupStore1573361825
numNetworkReqs393184153776
Power User HomeuiStartup5934201914713220368198785
load13091122204715313491593
domContentLoaded12871117200114513241575
domInteractive44213295334180
firstPaint220821778210262357
backgroundConnect186432011817210328895870
firstReactRender24177072539
initialActions104113
loadScripts1059911165813310781324
setupStore16685101828
numNetworkReqs19010132654218304
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2192172201220220
srpButtonToSrpForm97959819898
confirmSrpToPwForm22222202222
pwFormToMetricsScreen16161601616
metricsToWalletReadyScreen16161811718
doneButtonToHomeScreen70559377171763771
openAccountMenuToAccountListLoaded27902503292216129042922
total3937378340479840354047
Onboarding New WalletcreateWalletToSocialScreen2212182263223226
srpButtonToPwForm1101081132110113
createPwToRecoveryScreen989099
skipBackupToMetricsScreen41384634346
agreeButtonToOnboardingSuccess17161911719
doneButtonToAssetList58750768881683688
total98790210787710751078
Asset DetailsassetClickToPriceChart79798008080
total79798008080
Solana Asset DetailsassetClickToPriceChart82501122291112
total82501122291112
Import Srp HomeloginToHomeScreen2310228323351923172335
openAccountMenuAfterLogin553970116570
homeAfterImportWithNewWallet1721646253585823952535
total41553015524192347485241
Send TransactionsopenSendPageFromHome27272702727
selectTokenToSendFormLoaded29233553235
reviewTransactionToConfirmationPage1274719187041114831870
total1331777192040915461920
SwapopenSwapPageFromHome76381353483135
fetchAndDisplaySwapQuotes2697268227131227092713
total2773272928444227962844
🌐 Dapp Page Load Benchmarks

Current Commit: a073850 | Date: 3/16/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.04s (±46ms) 🟡 | historical mean value: 1.05s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 735ms (±60ms) 🟢 | historical mean value: 738ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 92ms (±127ms) 🟢 | historical mean value: 87ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.04s 46ms 1.01s 1.43s 1.07s 1.43s
domContentLoaded 735ms 60ms 707ms 1.29s 746ms 1.29s
firstPaint 92ms 127ms 64ms 1.35s 88ms 1.35s
firstContentfulPaint 92ms 127ms 64ms 1.35s 88ms 1.35s
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 398 Bytes (0.01%)
  • ui: 5 Bytes (0%)
  • common: 1.15 KiB (0.01%)

…store, fix tests

- Only check globalThis.self?.location?.href and compute isBackground when
  useFixtureStore is true; throw with clear error if href is missing
- Add comment that globalThis.self is used for both UI and service worker
- Tests: mock shared/lib/object.utils (not modules); expect throw when
  href empty or self undefined

Made-with: Cursor
@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Mar 16, 2026

Builds ready [81d4159]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account30526235638326356
total30526235638326356
Confirm Txconfirm_tx6054603660761460586076
total6054603660761460586076
Bridge User Actionsbridge_load_page25821529531277295
bridge_load_asset_picker2622602652265265
bridge_search_token77375279617781796
total1268123812942212831294
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup14731236195912015181642
load12171010172410512621382
domContentLoaded12101005161610012571375
domInteractive3018103212593
firstPaint169701274138216338
backgroundConnect22020031217224246
firstReactRender2114229212027
initialActions105123
loadScripts100780214099810471163
setupStore1374951620
numNetworkReqs403184164379
Power User HomeuiStartup5162189313298222362388877
load12501086160810512961466
domContentLoaded1226108015489412631420
domInteractive3418148213580
firstPaint246791459227267432
backgroundConnect17842878094167430754609
firstReactRender24165372640
initialActions104112
loadScripts101890013258810511217
setupStore1555571729
numNetworkReqs2178743359246330
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2202172253223225
srpButtonToSrpForm95939929799
confirmSrpToPwForm23212622426
pwFormToMetricsScreen15151601616
metricsToWalletReadyScreen16151711617
doneButtonToHomeScreen62059763216632632
openAccountMenuToAccountListLoaded3008290631419831123141
total3941391039963439433996
Onboarding New WalletcreateWalletToSocialScreen2212202231221223
srpButtonToPwForm1101071122110112
createPwToRecoveryScreen888088
skipBackupToMetricsScreen39394003940
agreeButtonToOnboardingSuccess16161601616
doneButtonToAssetList50848055228515552
total90487495633907956
Asset DetailsassetClickToPriceChart83778758787
total83778758787
Solana Asset DetailsassetClickToPriceChart1287020450162204
total1287020450162204
Import Srp HomeloginToHomeScreen2244217423035923022303
openAccountMenuAfterLogin654893167293
homeAfterImportWithNewWallet23762240252010624242520
total4646459047577947574757
Send TransactionsopenSendPageFromHome382356145356
selectTokenToSendFormLoaded29233863538
reviewTransactionToConfirmationPage1032862129418812261294
total1099918138220213051382
SwapopenSwapPageFromHome774994189094
fetchAndDisplaySwapQuotes270026892709727042709
total278727832794427942794
🌐 Dapp Page Load Benchmarks

Current Commit: 81d4159 | Date: 3/16/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 976ms (±51ms) 🟢 | historical mean value: 1.04s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 686ms (±61ms) 🟢 | historical mean value: 737ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 88ms (±121ms) 🟢 | historical mean value: 88ms ⬇️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 976ms 51ms 950ms 1.38s 989ms 1.38s
domContentLoaded 686ms 61ms 664ms 1.22s 692ms 1.22s
firstPaint 88ms 121ms 60ms 1.29s 84ms 1.29s
firstContentfulPaint 88ms 121ms 60ms 1.29s 84ms 1.29s
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 398 Bytes (0.01%)
  • ui: 17.41 KiB (0.2%)
  • common: 1.65 KiB (0.01%)

@gauthierpetetin gauthierpetetin marked this pull request as ready for review March 16, 2026 19:51
? new FixtureExtensionStore()
: new ExtensionStore(),
});
let isBackground = false;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: It could be confusing to leave this variable in the module scope where it might be re-used, when it's actually only set to the correct value in a narrow circumstance (when useFixtureStore is true). In all other cases it remains set to false even in the background process.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could do something like this, and create a function to construct the local store:

function createLocalStore() {
  const useFixtureStore =
    process.env.IN_TEST &&
    getManifestFlags().testing?.forceExtensionStore !== true;
  if (!useFixtureStore) {
    return new ExtensionStore();
  }
  
    // Use globalThis.self (not window) so this works in both the UI and the background/service worker, where window is undefined.
  const locationHref = globalThis.self?.location?.href;
  if (!locationHref) {
    throw new Error(
      'setup-initial-state-hooks: globalThis.self?.location?.href is not defined; expected to run in a document or service worker context.',
    );
  }
  const isBackground =
    getEnvironmentType(locationHref) === ENVIRONMENT_TYPE_BACKGROUND;
  return new FixtureExtensionStore({ initialize: isBackground })
}

That keeps the intermediary variables out of the global scope, and never leaves it with an invalid/misleading default value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, it's now updated here: 4468792

Move useFixtureStore, locationHref, and isBackground logic into
createLocalStore() so no misleading module-level isBackground default.
Addresses PR review feedback.

Made-with: Cursor
@sonarqubecloud
Copy link

@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Mar 17, 2026

Builds ready [1ec00b8]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account38029648985475489
total38029648985475489
Confirm Txconfirm_tx603860316046560396046
total603860316046560396046
Bridge User Actionsbridge_load_page24421130334258303
bridge_load_asset_picker2662572747272274
bridge_search_token76575177610775776
total126712601271512711271
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup14641228172210015071649
load1214102014669312511401
domContentLoaded1207101514579112461377
domInteractive3018137222688
firstPaint158701064117204274
backgroundConnect21819727613222246
firstReactRender21124872135
initialActions108124
loadScripts100481612538910441174
setupStore1374361625
numNetworkReqs393187153778
Power User HomeuiStartup5652210416821240664238040
load13431137188713813681627
domContentLoaded13251129185313213581580
domInteractive41212663835129
firstPaint227851873195284431
backgroundConnect187330511512220726425492
firstReactRender25194662736
initialActions104112
loadScripts1089905156212211221330
setupStore1563551725
numNetworkReqs21712037751241321
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2212202221221222
srpButtonToSrpForm96959719797
confirmSrpToPwForm23222412324
pwFormToMetricsScreen17161811818
metricsToWalletReadyScreen17161701717
doneButtonToHomeScreen64161468431684684
openAccountMenuToAccountListLoaded2928290929652629652965
total3914389739421739153942
Onboarding New WalletcreateWalletToSocialScreen2182162202218220
srpButtonToPwForm1101051144113114
createPwToRecoveryScreen889099
skipBackupToMetricsScreen41404214242
agreeButtonToOnboardingSuccess17161911819
doneButtonToAssetList51148253018530530
total90887994423921944
Asset DetailsassetClickToPriceChart70521052389105
total70521052389105
Solana Asset DetailsassetClickToPriceChart1177217336141173
total1177217336141173
Import Srp HomeloginToHomeScreen23352207257014124272570
openAccountMenuAfterLogin604871107071
homeAfterImportWithNewWallet23432233247210324162472
total47134487486914247854869
Send TransactionsopenSendPageFromHome532572196772
selectTokenToSendFormLoaded422872185472
reviewTransactionToConfirmationPage1141934132312912161323
total1236999144914813081449
SwapopenSwapPageFromHome1554922762207227
fetchAndDisplaySwapQuotes269026902691026912691
total2848273929136128972913
🌐 Dapp Page Load Benchmarks

Current Commit: 1ec00b8 | Date: 3/17/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.04s (±42ms) 🟡 | historical mean value: 1.03s ⬆️ (historical data)
  • domContentLoaded-> current mean value: 733ms (±62ms) 🟢 | historical mean value: 727ms ⬆️ (historical data)
  • firstContentfulPaint-> current mean value: 91ms (±129ms) 🟢 | historical mean value: 90ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.04s 42ms 1.01s 1.37s 1.07s 1.37s
domContentLoaded 733ms 62ms 707ms 1.30s 757ms 1.30s
firstPaint 91ms 129ms 64ms 1.37s 92ms 1.37s
firstContentfulPaint 91ms 129ms 64ms 1.37s 92ms 1.37s
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs
  • background: 398 Bytes (0.01%)
  • ui: 5 Bytes (0%)
  • common: 286 Bytes (0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size-M team-extension-platform Extension Platform team

Projects

Status: Needs dev review

Development

Successfully merging this pull request may close these issues.

3 participants