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

is server side rendering SSR supported? #196

Closed
sgratzl opened this issue Sep 17, 2020 · 3 comments
Closed

is server side rendering SSR supported? #196

sgratzl opened this issue Sep 17, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@sgratzl
Copy link

sgratzl commented Sep 17, 2020

I'm currently using next.js to generate a website and it uses SSR to render the pages beforehand. However, as expected the localstorage doesn't match when hydrating the DOM. Moreover, it throws since window is not defined in the server setting

@Akurganow
Copy link
Owner

@sgratzl This is a client-only solution and I haven't planned SSR support
But if you have ideas how it could be implemented I ready to discuss

@Akurganow Akurganow added the enhancement New feature or request label Sep 23, 2020
@sgratzl
Copy link
Author

sgratzl commented Sep 23, 2020

one approach is to have a construct like:

const [value, setValue] = useState(null);
useEffect(() => {
  if (window && window.localStorage) {
    setValue(...)
  }
});

However, this would enforce that everything is rendered twice. First time (server/hydrate) with no results and the second time with the current one

@Akurganow
Copy link
Owner

Check window existence is a solution only for localStorage and sessionStorage but the hook works with any storage that implements Storage interface and it's not always something that's in the window and as you said this would enforce everything rendering twice
It should be the Storage level solution and it seems like there is a solution to make the first rendering happen with an initial value, give me time to think about it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants