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

fix: calling getVariableValue in server actions #1014

Merged

Conversation

ajwootto
Copy link
Contributor

@ajwootto ajwootto commented Dec 16, 2024

  • Next SDK was previously relying on the ability to mutate the returned object of a specific React "cache" call, in order to set and get a value that can be used across various functions
  • first of all, this pattern is apparently discouraged in general apparently, they want us to write code using "cache" that assumes the result is re-derivable at any time if the cache were suddenly cleared (ie. dont rely on the object returned from cache always being the same or always being there)
  • second of all, cache doesnt work in server actions
  • so to fix using the SDK in server actions (and middleware), remove the use of the mutating cached context and simply pass the client around to the places its needed
  • remove the getVariableValue etc. methods that were exported from their own files and instead just directly call the client's methods inside the "setupDevCycle" scope

Copy link

vercel bot commented Dec 16, 2024

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

Name Status Preview Comments Updated (UTC)
js-sdks-web-elements ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 16, 2024 8:37pm
js-sdks-with-provider ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 16, 2024 8:37pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
js-sdks-next-js-page-router ⬜️ Ignored (Inspect) Dec 16, 2024 8:37pm

@ajwootto ajwootto requested a review from a team December 16, 2024 20:25
@ajwootto ajwootto marked this pull request as ready for review December 16, 2024 20:25
@ajwootto ajwootto changed the title fix calling getVariableValue in server actions fix: calling getVariableValue in server actions Dec 16, 2024
@@ -54,7 +76,10 @@ export const setupDevCycle = <
clientSDKKey,
userGetter,
options,
)
).then((result) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this function be async?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, this is explicitly passing an unresolved promise

@ajwootto ajwootto enabled auto-merge (squash) December 16, 2024 20:55
@ajwootto ajwootto merged commit b165bc2 into main Dec 16, 2024
11 checks passed
@ajwootto ajwootto deleted the adam/rnd-195-nextjs-sdk-does-not-work-in-server-actions branch December 16, 2024 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants