-
Notifications
You must be signed in to change notification settings - Fork 314
SSR #1905
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 #1905
Conversation
8e4e9fd to
cf80308
Compare
|
View Vercel preview at instant-www-js-drewh-ssr-jsv.vercel.app. |
7ce8b7d to
cf4c75d
Compare
stopachka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @drew-harris !
72e391b to
9d33768
Compare
stopachka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good to me!
332a95b to
4e70126
Compare
fixes after new peristed objects format classname order - prettier add copy buttons to docs fix build issues after rebase fix more build issues after rebase fix infinite recurse with useauth via ssr
a90ce8f to
45343ca
Compare
45343ca to
21bc528
Compare
stopachka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ship it sir!!!
The PR adds a utility function exported from core, that allows the user to sync auth state to a cookie that a server can read.
It also creates a
Frameworkclass in core that makes http requests to get triples and keeps a cache of results. It's designed to be framework agnostic, if we want to add ssr to other frameworks, other cool things.I created a new init function / suspense provider under a /nextjs import in the react package.
Important
I renamed a backend route from
/runtime/queryto/runtime/framework/queryto make it more clear that the route is meant to only be used with the FrameworkClient class. It also changes so that if an incorrect refresh token is used, it will ignore the refresh token all together and query anonymously.Example Repo Readme:
Version to try: 0.22.92-experimental.drewh-ssr.20348370870.1
InstantDB Next.JS SSR Example
This repo demonstrates NextJS SSR and cookie sync. Built on top of
create-instant-app's NextJS todo example.Setup Cookie Sync (Optional)
src/app/api/instant/route.tslike so:src/lib/db.tsSetup SSR
Create an InstantProvider
Using SSR
Instead of using
db.useQueryyou can usedb.useSuspenseQueryinstead.If a page is rendering on the server, the server will make an HTTP request to Instant to retrieve the results before rendering.
If the page is running on the client, it will re-use the existing webhook connection.
SSR and Auth
The
db.useAuthfunction works as normal, except that if you provide the user object to InstantSuspenseProvider higher in the component tree, it will skip a loading state.This also works with <db.SignedIn> and <db.SignedOut> allowing you to skip any flashes of loading spinners or blank pages.