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

Hydration Issue nextjs #65

Open
Leykwan132 opened this issue Aug 30, 2022 · 6 comments
Open

Hydration Issue nextjs #65

Leykwan132 opened this issue Aug 30, 2022 · 6 comments

Comments

@Leykwan132
Copy link

Leykwan132 commented Aug 30, 2022

https://stackoverflow.com/questions/68110629/nextjs-react-recoil-persist-values-in-local-storage-initial-page-load-in-wrong/73536131?noredirect=1#comment129857349_73536131

I've gone through this question but the value stored in the state of my atom is an object that is returned by an API call which is relatively complex compared to the boolean value mentioned in the stackoverflow question above. Unlike the case above, I don't think I can set the value of SSR to be the same as the CSR. How should I handle the hydration? Or can I just ignore the issue? WIll it impact the website when it is deployed to production?

@zero734kr
Copy link

Any progress here? Personally I ended up moving the recoil state call to another wrapper component and forced to CSR with next/dynamic like below:

import dynamic from 'next/dynamic'

// ... 
const SomeRecoilStateWrapper = dynamic(
  () => Promise.resolve(SomeRecoilStateContainer),
  { ssr: false }
)

function SomeRecoilStateContainer () {
  const value = useRecoilValue(...) // recoil atom using recoil-persist
  
  // ...
}

But I would really like to see a better solution here

@RizqiSyahrendra
Copy link

I thought this kind of problem has been fixed on #24 , don't know why this problem has still appeared now

@joacub
Copy link

joacub commented Nov 24, 2022

there is a missmatch error using recoil, when you use concurrent mode or startTransition, recoil-persist get hydrated before all render and this does not match with server at all ofcourse

@kensoz
Copy link

kensoz commented Dec 7, 2022

same here.
in my case atom is an Array.

Here is a simplified code, and sorry for my bad English.
When the button is clicked, the ID of the clicked item will be saved to atom recoilTest array.
Then the icon below will determine whether to display a star or a heart according to the ID in atom recoilTest array.
Click, then refresh the page, there will be a Hydration Issue.

.tsx

...
<button type='button' onClick={() => onClick( {id: e.id} )}>
  <FontAwesomeIcon icon={recoilTest.findIndex((i) => i.id === e.id) !== -1 ? faStar : faHeart} />
</button>
...

recoil.ts

const { persistAtom } = recoilPersist()

export const recoilTest = atom({
  key: 'recoilTest',
  default: [{id: '1'}],
  effects_UNSTABLE: [persistAtom],
})

next: 12.3.1
react: 18.2.0
recoil: ^0.7.5
recoil-persist: ^4.2.0

@joshephan
Copy link

same here.

this issue has been quite long nobody answer :(

is recoil project dead?

@polemius
Copy link
Owner

I have added a section to README

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

No branches or pull requests

7 participants