-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CPU spinning + browser unresponsiveness on network switch #861
Comments
It’s a good question as to what should happen. The network for a Provider is never meant to change. When the network changes, a new Provider should be instantiated... but if it isn’t, these cases are hard to efficiently detect. I’ll think of something today and try a few things out. |
Related to #495 I've added some basic support for Providers that support the network changing. To enable it, the network must be specified as Once that is done, the If a Provider is not marked as I'm adding a section in the docs on this now. Keep in mind there are potentially a lot of edge cases to handle if you are supporting network changes. Also, to simplify life, and get back to the old Metamask behaviour of refreshing the page on network change (most regular users won't be switching networks; so this won't impact them): // Force page refreshes on network changes
{
// The "any" network will allow spontaneous network changes
const provider = new ethers.providers.Web3Provider(window.ethereum, "any");
provider.on("network", (newNetwork, oldNetwork) => {
// When a Provider makes its initial connection, it emits a "network"
// event with a null oldNetwork along with the newNetwork. So, if the
// oldNetwork exists, it represents a changing network
if (oldNetwork) {
window.location.reload();
}
});
} At a minimum, most applications that support network changes will want to The CI is running right now, and once all the tests pass, I'll publish to npm. :) |
The CI is done, try out 5.0.0-beta.191 and let me know if it works for you. :) |
I posted in the other issue. Basically, the lock files need to be reset. Let me know if you still have any problems. Sorry for the inconvenience. |
Tried out listening to the |
Glad to hear it! :) Closing now, but reach out if there are any further issues. Thanks! :) |
In our dapp that uses ethers 5.0.0-beta.187 + Metamask + Chrome or Firefox, we are observing the following:
base-provider.js
:One example of values int he loop are
this._emitted.block
of 54 andblockNumber
of 8,012,600. With these values, the loop will iterate 8 million times.The text was updated successfully, but these errors were encountered: