Skip to content

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

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion npm-packages/convex/src/nextjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,23 @@ function setupClient(options: NextjsOptions) {
}

function getConvexUrl(
/**
* The URL of the Convex deployment to use for the function call.
*
* Defaults to `process.env.NEXT_PUBLIC_CONVEX_URL` if not provided.
*
* Explicity passing undefined here (such as in broken ENV variables) will throw an error in the future
*/
deploymentUrl: string | undefined,
skipConvexDeploymentUrlCheck: boolean,
) {
const url = deploymentUrl ?? process.env.NEXT_PUBLIC_CONVEX_URL;
if (arguments.length === 0) {
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?");
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, makes sense

}
const url = deploymentUrl;
const isFromEnv = deploymentUrl === undefined;
if (typeof url !== "string") {
throw new Error(
Expand Down