Git Product home page Git Product logo

Comments (13)

dai-shi avatar dai-shi commented on May 3, 2024 1

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.

from zustand.

drcmda avatar drcmda commented on May 3, 2024

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

from zustand.

codemilli avatar codemilli commented on May 3, 2024

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?

from zustand.

drcmda avatar drcmda commented on May 3, 2024

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

from zustand.

codemilli avatar codemilli commented on May 3, 2024

@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:

from zustand.

drcmda avatar drcmda commented on May 3, 2024

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.

from zustand.

codemilli avatar codemilli commented on May 3, 2024

@drcmda
Okay ! i will make a pr :D

from zustand.

themre avatar themre commented on May 3, 2024

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

from zustand.

janek26 avatar janek26 commented on May 3, 2024

vercel/next.js#11222

from zustand.

ahmedu007 avatar ahmedu007 commented on May 3, 2024

That PR never landed in the repo 😞

from zustand.

maxwaiyaki avatar maxwaiyaki commented on May 3, 2024

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

from zustand.

dai-shi avatar dai-shi commented on May 3, 2024

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.

from zustand.

dai-shi avatar dai-shi commented on May 3, 2024

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

from zustand.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.