-
Notifications
You must be signed in to change notification settings - Fork 287
fix: #24 Next.js SDK bad URL defaulting #135
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
Conversation
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.
Unfortunately this doesn't work, in JavaScript passing undefined
uses the default value just like not passing the variable!
tomb@macbookpro convex % node
Welcome to Node.js v18.20.6.
Type ".help" for more information.
> function foo(a=1) { return a; }
undefined
> foo(3)
3
> foo()
1
> foo(undefined)
1
I had a version of this in that caused a problem with Convex Auth, we could merge that again if we can confirm the Convex Auth issue is fixed?
I apologize, I thought I tested it pretty well the other day, can you see if you can break this function any way? function getConvexUrl(
deploymentUrl?: string | undefined
) {
if (arguments.length === 0) {
deploymentUrl = "ENV FALLBACK";
}
else if (deploymentUrl === undefined) { // Should skip over this if it hits the first one
return `deploymentUrl is undefined, are your environment variables set?`;
}
return deploymentUrl;
}
console.log(getConvexUrl(), getConvexUrl(undefined), getConvexUrl("hello")); This is what the output should look like: ENV FALLBACK
deploymentUrl is undefined, are your environment variables set?
hello |
Cool, and thanks to get-convex/convex-auth#156 looks like the problem I had last time has been addressed. I think we need to roll it out carefully though since until now it was possible to pass convex-backend/npm-packages/convex/src/nextjs/index.ts Lines 65 to 69 in ade99cf
undefined will throw an error in the future? And we'll make it an error in a few versions, probably the next minor version bump that requires explicit upgrade instructions so we can call it out.
It would be nice to add a TypeScript error when passing |
…changes in minor versions
Yeah, it would be a breaking change if we did that lol, how does it look now? |
deploymentUrl = process.env.NEXT_PUBLIC_CONVEX_URL; | ||
} | ||
else if (deploymentUrl === undefined) { // It will skip over this check if it hits the first one | ||
console.error("deploymentUrl is undefined, are your environment variables set?"); |
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.
if we've avoiding breaking people we need to still set deploymentUrl = process.env.NEXT_PUBLIC_CONVEX_URL
here, what you have is what we'll do in ~month or so
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.
Right, makes sense
Looks good, just one issue that I'll fix when I port it over. Thank you! |
No worries! |
added in cefd789, thank you! |
Fixing the issue in #24 , should be a bit less error prone now
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.