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

Issues with server-side vs client-side page loads #129

Closed
kasbah opened this issue May 30, 2021 · 9 comments · Fixed by #208
Closed

Issues with server-side vs client-side page loads #129

kasbah opened this issue May 30, 2021 · 9 comments · Fixed by #208
Milestone

Comments

@kasbah
Copy link
Member

kasbah commented May 30, 2021

On some page transitions the user isn't loaded properly if you change page client-side. Especially noticeable around the user's logged-in state and project ownership (i.e. the file selection buttons don't show up unless you reload). Might this be because of heavy use of getServerSideProps. Would getInitialProps be a better fit to what we are doing? What exactly is the difference?

@kasbah
Copy link
Member Author

kasbah commented May 30, 2021

Found this discussion: vercel/next.js#11211

@kasbah
Copy link
Member Author

kasbah commented Jun 3, 2021

So @AbdulrhmnGhanem, you linked me this change which solves this in a way. It does feel like a work-around though. Can you explain why this is needed. From discussions above it shouldn't be needed.

I also came across this issue where a lot of people are complaining about extra fetching needed for getServerSideProps and NextJS creators mention getInitialProps won't be removed any time soon. Maybe getInitialProps is a better solution for us?

@AbdulrhmnGhanem
Copy link
Member

To check the user, who is making the request, not the project owner, req?.session?.user?.username is used. For client-side navigation the value of req.session is null, this only happens in production as in development all navigations rebuild the page.

Maybe getInitialProps is a better solution for us?

The docs recommend using getStaticProps, this the only reason that made me use it. In theory, renaming getStaticProps to getInitialProps will be the only required change to start using it.

@kasbah
Copy link
Member Author

kasbah commented Jun 7, 2021

That makes sense. We need to have a good way to persist the session that doesn't depend on req.session being present then.

The question about switching from getStaticProps to getInitialProps seems to be mainly a performance trade-off, initial bundle size vs page-transition requests, so let's hold off on that.

@AbdulrhmnGhanem
Copy link
Member

AbdulrhmnGhanem commented Sep 19, 2021

In 634c77b, I tried getServerSideProps for multi-part projects and getInitialProps for normal projects. And there's no difference; the req object isn't available with client-side navigation, it's mentioned in the documentation for getInitialProps but not with getStaticProps so I had to test it.

To unify the logic I think we should do anything that relies on session on the client-side only.

@AbdulrhmnGhanem
Copy link
Member

Also, take a look at next-express. Will it work given how the token is passed from gitea now?

@kasbah
Copy link
Member Author

kasbah commented Sep 20, 2021

req not being there is expected to me. That's why I attached the session to window in my initial implementation (maybe you are still doing something akin to this, I'm not sure). To me there isn't really a problem here, it just needs to be handled correctly for both cases, server and client side, req being there and not. (Don't have time to look into next-express right now but at a quick glance it's not going to solve any of this for us.)

To unify the logic I think we should do anything that relies on session on the client-side only.

That doesn't make sense to me. It's there as req.session on the server-side, no?

@AbdulrhmnGhanem
Copy link
Member

This means I will duplicate the logic on the client-side and server-side for anything that accesses the session, I have no problem with this but you didn't like it before.

@kasbah
Copy link
Member Author

kasbah commented Sep 20, 2021 via email

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 a pull request may close this issue.

2 participants