Skip to content

fix: prevent glitch in default transport with a "connecting" state#1359

Merged
elribonazo merged 2 commits into
mainfrom
fix/multichain-default-transport-glitch
Oct 3, 2025
Merged

fix: prevent glitch in default transport with a "connecting" state#1359
elribonazo merged 2 commits into
mainfrom
fix/multichain-default-transport-glitch

Conversation

@elribonazo

@elribonazo elribonazo commented Oct 3, 2025

Copy link
Copy Markdown
Contributor

Explanation

There is currently an issue in the multichain sdk, affecting the browser.
If the user clicks connect and has no extension installed the ShowInstall modal will display on screen.

When this happens, we automatically setup the Mobile Wallet protocol transport as used transport, the glitch happens if the user clicks refresh screen without closing the install modal. If that happens, we will have stored MWP as default transport when we have no proof this is the transport the user wants.

Upon the screen refresh it automatically tries to connect to MWP but it has nothing to connect into, because connection never succeeded.

This buggy behavior is fixed by listening to window.addEventListener('beforeunload') event and removing the transport if the modal is still visible.

Important to mention that we have no guarantees really that we will be able to run
await this.storage.removeTransport(); and that call will resolve before browser refreshes. I've tested and we do provide enough time to complete, just a note here...

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

Note

Adds a beforeunload handler to remove stored transport when the install modal is open and manages its lifecycle to prevent stale connections and leaks.

  • MultichainSDK (packages/sdk-multichain/src/multichain/index.ts):
    • Add onBeforeUnload to remove stored transport if the install modal is visible.
    • Introduce one-time beforeunload listener management:
      • createBeforeUnloadListener registers/unregisters the handler; stored in __beforeUnloadListener.
      • Listener initialized once in showInstallModal and disposed in disconnect.
    • disconnect now invokes and clears the beforeunload listener before tearing down transport and state.

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

@elribonazo elribonazo marked this pull request as ready for review October 3, 2025 08:45
@elribonazo elribonazo requested a review from a team as a code owner October 3, 2025 08:45
@elribonazo elribonazo self-assigned this Oct 3, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@elribonazo elribonazo force-pushed the fix/multichain-default-transport-glitch branch from 6d550e0 to 97bd3a5 Compare October 3, 2025 11:17
@codecov

codecov Bot commented Oct 3, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.99%. Comparing base (3ff7401) to head (97bd3a5).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1359      +/-   ##
==========================================
- Coverage   75.10%   74.99%   -0.12%     
==========================================
  Files         184      184              
  Lines        4519     4519              
  Branches     1108     1108              
==========================================
- Hits         3394     3389       -5     
- Misses       1125     1130       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

sonarqubecloud Bot commented Oct 3, 2025

Copy link
Copy Markdown

@elribonazo elribonazo merged commit b2e5984 into main Oct 3, 2025
43 of 44 checks passed
@elribonazo elribonazo deleted the fix/multichain-default-transport-glitch branch October 3, 2025 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants