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

SSR example #11

Closed
mcansh opened this issue Apr 16, 2019 · 13 comments
Closed

SSR example #11

mcansh opened this issue Apr 16, 2019 · 13 comments
Labels
help wanted Please someone help on this

Comments

@mcansh
Copy link

mcansh commented Apr 16, 2019

I think I almost have it working using a tweaked version of the redux next.js example, but the state gets wiped out on the client

@drcmda
Copy link
Member

drcmda commented Apr 16, 2019

I think I would need some help for that, I don’t understand ssr good enough, but would gladly welcome prs.

@JeremyRH JeremyRH added the help wanted Please someone help on this label May 5, 2019
@codemilli
Copy link
Contributor

I tried to set the default state with storeApi but This package is based on React Hooks and using useLayoutEffect hooks.
That is problem that makes server side rendering broken.
Is there any other way to set default state dynamically without update DOM?

@drcmda
Copy link
Member

drcmda commented Jun 21, 2019

could you explain why useLayoutEffect is a problem when it comes to SSR?

@codemilli
Copy link
Contributor

codemilli commented Jun 21, 2019

@drcmda

Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client. See https://fb.me/react-uselayouteffect-ssr for common fixes.

Above error message keeps being logged.
I found react-redux uses useLayoutEffect only if window is defined or uses useEffect.

typeof window !== 'undefined' ? useLayoutEffect : useEffect

Can it be the solution to this case?

Related issue:

@drcmda
Copy link
Member

drcmda commented Jun 21, 2019

yes, i guess that could be. could you try? you can copy this: https://unpkg.com/[email protected]/dist/esm/index.js into a local "zustand.js" and change it to useEffect. if it works i'll implement the patch.

@codemilli
Copy link
Contributor

@drcmda
Okay ! i will make a pr :D

@themre
Copy link

themre commented Mar 5, 2020

can this issue be closed? does it work? thanks!

@janek26
Copy link

janek26 commented Mar 20, 2020

vercel/next.js#11222

@ahmedu007
Copy link

That PR never landed in the repo 😞

@maxwaiyaki
Copy link

Can we revisit this issue?? Seems there was never a solution implemented.

@dai-shi
Copy link
Member

dai-shi commented Aug 23, 2020

Hi, is it about hydration not working, or is it completely broken with next? Would you like to file a new issue please?

Note: useIsoLayoutEffect is just a hack to eliminate the warning message. It doesn't do anything for SSR.

@dai-shi
Copy link
Member

dai-shi commented Sep 9, 2020

Let me reopen this.

@jd327
#182 (comment)

I'm currently supplementing with createContext and useContext for anything SSR-related

Where can I find such examples with useContext, so that I can start learning? There must be something in the nextjs docs.

@dai-shi dai-shi reopened this Sep 9, 2020
@dai-shi
Copy link
Member

dai-shi commented Sep 13, 2020

I changed my mind. Let me close this and continue discussion in #182.

@dai-shi dai-shi closed this as completed Sep 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Please someone help on this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants