Skip to content
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

Patch useLocalStorage setting the right initial value to avoid a hydration error #356

Merged
merged 4 commits into from
May 31, 2023

Conversation

damianmarti
Copy link
Member

fixes #340 (if we want to fix it with a patch to usehooks-ts)

Copy link
Collaborator

@technophile-04 technophile-04 left a comment

Choose a reason for hiding this comment

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

Tysm Damu !!

This might be the problem with only my machine (even previously I had some issues picking the right dependencies) :

Screen.Recording.2023-05-30.at.11.10.38.AM.mov

I have created the useLocalStorage-patchTest branch which branches from this branch and added basic useLocalStorage to test

Step to reproduce :
1.

git pull
git switch useLocalStorage-patchTest
yarn install
  1. click the greeting button on Home page( this will update isHello localStorage state to false ) and then refresh the page.

Now this might be the problem with only my machine so would love it if someone could test it

But, the changes look good to me 🙌

@rin-st
Copy link
Member

rin-st commented May 30, 2023

It doesn't work for me too. But it works if I copy-paste hook to hooks directory and change storedValue to initialValue

And it shows initial value for some milliseconds

2023-05-30.15.25.12.mov

@damianmarti
Copy link
Member Author

It doesn't work for me too. But it works if I copy-paste hook to hooks directory and change storedValue to initialValue

And it shows initial value for some milliseconds

2023-05-30.15.25.12.mov

@rin-st did you run yarn install before testing it?

@rin-st
Copy link
Member

rin-st commented May 30, 2023

@damianmarti yes

I found solution: yarnpkg/berry#4231 (comment) this helped. If I change resolutions to "usehooks-ts@^2.7.2": "patch:usehooks-ts@npm:^2.7.2#./.yarn/patches/usehooks-ts-npm-2.7.2-fceffe0e43.patch" it works

@damianmarti
Copy link
Member Author

@damianmarti yes

I found solution: yarnpkg/berry#4231 (comment) this helped. If I change resolutions to "usehooks-ts@^2.7.2": "patch:usehooks-ts@npm:^2.7.2#./.yarn/patches/usehooks-ts-npm-2.7.2-fceffe0e43.patch" it works

I'm not sure about it. Maybe @sverps @carletex or @technophile-04 have something to say...

@sverps
Copy link
Collaborator

sverps commented May 31, 2023

I had the same issue as @rin-st , seems like the patch generated a faulty resolutions line (with a url-encoded ^ sign, rather than the actual one). I committed the fix from @rin-st , I think we can merge it like this 👍

@carletex
Copy link
Member

It works! Thank you all!

@carletex carletex merged commit 76c531e into main May 31, 2023
@carletex carletex deleted the use-local-storage-patch branch May 31, 2023 10:46
This was referenced Jun 29, 2023
kmjones1979 added a commit that referenced this pull request Jul 3, 2023
* Update SE-2 nomenclautre  (#317)

* Fix autoConnect when contract not deployed (#292)

* oxford comma lol

* Fix icon visibility on dark mode in EtherInput (#320)

* Update README: Add Vercel ENV var to disable type/lint checking (#327)

* Fix typo (#334)

Fix typo at code snippet

* README: Updated SE-2 custom hook section (#330)

Co-authored-by: KcPele <[email protected]>
Co-authored-by: Shiv Bhonde <[email protected]>
Co-authored-by: Carlos Sánchez <[email protected]>

* Remove duplicated HINT on README (#335)

* PR and Issue templates (#329)

* Native currency symbol and price as per target network (#322)

* useAppStore => useGlobalState (#338)

* Event history filter type (#333)

* fix: event history filter type

Fixes #332

* fix: make scaffold event history config separate type

* fix: prettier broke due to invalid syntax

* fix: ts error after generating contract

* Indexed prop + example

---------

Co-authored-by: Carlos Sánchez <[email protected]>

* Update README: custom hooks section (#339)

* fix: assert type as Abi to avoid ts error (#350)

* fix: assert type as Abi to avoid ts error

Fixes #344

* assert type as Abi to avoid ts error on useScaffoldContract

---------

Co-authored-by: Carlos Sánchez <[email protected]>

* Fix useEffect filter dep on event hook (#349)

* Block confirmation options / callback for useScaffoldContractWrite (#348)

* Patch useLocalStorage setting the right initial value to avoid a hydration error (#356)

Co-authored-by: sverps <[email protected]>

* Save selected contract to local storage (#326)

* Save selected contract to local storage

* refactor: Replaced native localStorage with useLocalStorage from usehooks-ts

* Fixed empty string parameter error.

* Updated parameter requirements to fix issue.

* Fixed error.

* Fixed parameter assignment error.

* Use useLocalStorage to save selected contract

---------

Co-authored-by: Damian <[email protected]>

* Refactor meta tags into separate component and add default thumbnail / image (#359)

* Hotfix: thumbnail.png => thumbnail.jpg

* Local Block Explorer (#351)

Co-authored-by: Shiv Bhonde <[email protected]>

* Fix daisyUI dropdown on IOS (#342)

* allow `overrides` in useScaffoldContractWrite (#345)

* allow overrides for useScaffoldContractWrite

* spread overrides and restConfig separately

* feat: proactively disable read hook when it would result in error (#250)

Fixes #249

Co-authored-by: Shiv Bhonde | shivbhonde.eth <[email protected]>

* Size prop on Address component (#365)


Co-authored-by: Carlos Sánchez <[email protected]>

* Generate TS ABIs from deploy script (#368)

* enable solidity optimizer by default (#360)

* fix(Balance): font-size of symbol should be relative to current font-size, not document root (#375)

* fix(contract.ts): very long abi's now no longer go over type instantiation limit (#377)

Fixes #374

* fix(contract.ts): improve missing config check (#372)

Fixes #371

* fix listner types error when contracts missing (#379)

* zkSyncEra Testnet config (#383)

* Upgrade hardhat-deploy to 0.11.26 where zkSync is supported

* Dependency for @matterlabs/hardhat-zksync-solc

* Add zkSyncEraTestnet to networks

* Import @matterlabs/hardhat-zksync-solc

* Add artifacts-zk and cache-zk to gitignore

* yarn install

* Add zkSync mainnet config

* add hardhat-zksync-verify for contract verification

---------

Co-authored-by: moltam89 <[email protected]>
Co-authored-by: Damian <[email protected]>
Co-authored-by: Shiv Bhonde <[email protected]>

* allow writeAsync by useScaffoldContractWrite to be called with updated args (#385)

* update wagmi & rainbow for walletConnectV2 (#381)

* meged changes from main, additional configuration in subgraph.yaml

---------

Co-authored-by: Shiv Bhonde | shivbhonde.eth <[email protected]>
Co-authored-by: Austin Griffith <[email protected]>
Co-authored-by: Kevin Joshi <[email protected]>
Co-authored-by: Carlos Sánchez <[email protected]>
Co-authored-by: AlehN <[email protected]>
Co-authored-by: Pablo Alayeto <[email protected]>
Co-authored-by: KcPele <[email protected]>
Co-authored-by: Samuel | solidixen.eth <[email protected]>
Co-authored-by: Eda Akturk <[email protected]>
Co-authored-by: Tamas Molnar <[email protected]>
Co-authored-by: Damian Martinelli <[email protected]>
Co-authored-by: Alexander <[email protected]>
Co-authored-by: port <[email protected]>
Co-authored-by: moltam89 <[email protected]>
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.

bug: hydration fails due to mismatch caused by usehooks-ts bug
5 participants