scaffold-eth / scaffold-eth-2

Open source forkable Ethereum dev stack
https://scaffoldeth.io
MIT License
1.4k stars 883 forks source link

bug: Debug tabs behavior #939

Closed rin-st closed 2 weeks ago

rin-st commented 2 months ago

Is there an existing issue for this?

Which method was used to setup Scaffold-ETH 2 ?

git clone

Current Behavior

While working on https://github.com/scaffold-eth/scaffold-eth-2/pull/933 I found very strange behavior: whenever I click on tab with contract, it always change to YourContract tab.

https://github.com/user-attachments/assets/0b67d24f-dcb2-4b53-b0f2-771051dedb43

It's not because of its index or alphabetical order, it's always YourContract (if you have that tab, of course). Clearing localstorage doesn't help

Expected Behavior

Clicked contract tab should be chosen

Steps To Reproduce

I debugged it and understood that it was because of my other browser tab, which had only YourContract. So, steps:

Anything else?

Not sure if we need to fix it for now since it's relatively rare case and not so easy to fix. But at least we know what causes this

rin-st commented 2 months ago

The bug is not related to the mentioned PR, it also works on main

technophile-04 commented 2 weeks ago

Thanks @rin-st!! So the summary is that if this problem occurs people need to make sure they close all other browser TABs with http://localhost:3000 and then refresh the latest one and it should start working. Just tried this and works nicely.

Umm I think instead of relying on usehooks-ts useLocalStorage logic maybe we should write a our custom simple logic for DebugContracts.

The reason I feel usehooks useLocalstorage have this problem is because they are listening to localstroage for all tabs and keeping them in sync :

Screenshot 2024-10-28 at 10 39 34 AM

But since the outdated tab doesn't have the new contract name, it updates the contractName to contractName[0] in outdated tab and latest tab listen to those changes and also updates it.