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

feat: nextjs sdk #586

Merged
merged 36 commits into from
Dec 4, 2023
Merged

feat: nextjs sdk #586

merged 36 commits into from
Dec 4, 2023

Conversation

ajwootto
Copy link
Contributor

@ajwootto ajwootto commented Oct 24, 2023

  • Add Next JS SDK supporting App Router
  • update example app to use it

@vercel
Copy link

vercel bot commented Oct 24, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
js-sdks-next-js ❌ Failed (Inspect) Dec 4, 2023 3:33pm
js-sdks-next-js-page-router ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 4, 2023 3:33pm
js-sdks-web-elements ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 4, 2023 3:33pm
js-sdks-with-provider ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 4, 2023 3:33pm

Copy link
Contributor Author

ajwootto commented Oct 24, 2023

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

return (
<html lang="en">
<body>
<DevCycleClientProvider
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a server component which handles initializing and fetching config etc. on serverside, making variables available to server components

It also renders a clientside provider with a bootstrapped client that uses the server's config data, guaranteeing hydration consistency. That bootstrapped client is also used on the server for rendering the first pass of client components

@@ -38,6 +45,7 @@ export class DVCPopulatedUser implements DevCycleUser {
options: DevCycleOptions,
staticData?: StaticData,
anonymousUserId?: string,
headerUserAgent?: string,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accept a user agent from outside so that the serverside can tell us what the user agent should be

sdk/js/src/User.ts Outdated Show resolved Hide resolved
* @param config
* @param user
*/
synchronizeBootstrapData(config: BucketedUserConfig, user: DevCycleUser) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding this because once the client has rendered the first time, subsequent refresh + rerenders of server content will not replace the existing bootstrapped config if the server has found a new one. This method is called each time the serialized context the server is passing to the client is changed, so that the client gets updated with the new config and user that the server was using during its last rendering pass

@@ -167,7 +170,10 @@ export class DevCycleClient<
}
this.initializeTriggered = true

const storedAnonymousId = await this.store.loadAnonUserId()
// don't wait to load anon id if we're being provided with a real one
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to fix a problem where initializing a bootstrapped client couldn't be used for variable evaluation until the next tick, because the config wasn't set until after this call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants