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

Statery is broken in Next.js #30

Closed
trezy opened this issue Aug 28, 2023 · 7 comments · Fixed by #31
Closed

Statery is broken in Next.js #30

trezy opened this issue Aug 28, 2023 · 7 comments · Fixed by #31
Assignees
Labels
bug Something isn't working

Comments

@trezy
Copy link

trezy commented Aug 28, 2023

I tried using Statery in a fresh Next.js app and encountered this error...

Error: Missing getServerSnapshot, which is required for server-rendered content. Will revert to client rendering.

I've already tracked down the issue: updating to useSyncExternalStore (issue #9 and PR #27). More specifically, the issue is that Statery isn't providing a 3rd argument to the hook, getServerSnapshot.

Now, React states that this 3rd argument is optional, and in the error message states that it will revert to client rendering. Next.js should be reverting to client rendering for the affected components, but it's not. As a result, this error prevents anything from being loaded at all.

Ideally, this issue should be fixed in Next.js so that nobody encounters it again. I've created an issue on that repo to track as well, but I expect it'll take quite some time before we see a fix. I'm hoping we can come up with a solution specifically for Statery in the meantime.

FWIW, several other projects have encountered and solved this same issue, so it's not exactly novel. I'll link to a handful of issues/commits where it was discussed/fixed elsewhere.

Project Issue PR or commit
Zustand #886 5a0b40
react-rxjs #305 #306
Apollo Client #9623 #9652
Amplify UI #1780 #1798
@trezy
Copy link
Author

trezy commented Aug 28, 2023

Temporary workaround is just to rollback to v0.6.3.

@hmans
Copy link
Owner

hmans commented Aug 29, 2023

Thanks, I'll take a look. I might need a little bit of time until I get around to it as I'm about to start a new job, but I'll try. Thank you very much for the detailed report, and all the extra links to how other projects tackled it.

(Pinging @smartinio, simply because we were discussing this change a while ago and weren't sure what the repercussions would be.)

Anyone encountering this bug, please use version 0.6.3 for now until we figure this out. Thanks!

@hmans hmans self-assigned this Aug 29, 2023
@hmans hmans added the bug Something isn't working label Aug 29, 2023
@smartinio
Copy link
Contributor

@hmans Created a PR with a fix and a server-side test. Verified locally that it works as well.

@daveschumaker Feel free to test it on your end too.

@daveschumaker
Copy link
Contributor

Nice work! I imported it into my Next JS v13 app and it works in both SSR and client contexts. Thanks for tackling this!

@smartinio
Copy link
Contributor

Sweet, no worries! Not sure how I ended up tagging you @daveschumaker but I meant to tag the OP @trezy 😅

@trezy
Copy link
Author

trezy commented Aug 30, 2023

@smartinio Yup, looks great! I tested it locally and it works like a dream. 😁

@hmans hmans closed this as completed in #31 Aug 30, 2023
@hmans
Copy link
Owner

hmans commented Aug 30, 2023

Thanks everyone for jumping in, especially @smartinio for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants