-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: construct serverEnv
, like we do with clientEnv
#1000
#1021
Conversation
🦋 Changeset detectedLatest commit: 4596004 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://create-t3-app-git-fork-ksv-vc-iduuck-issue-1000-t3-oss.vercel.app/ |
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.
We shouldnt need 2 separate objects right? Destruction can be in a single object shared with both server and client?
Ideally some comment saying you only need manual destruction for certain use-cases, and not require all envs to be destructured, i.e:
// schema.mjs
const destructured = {
FOO: process.env.FOO,
NEXT_PUBLIC_BAR: process.env.NEXT_PUBLIC_BAR,
}
const serverSchema = z.object({
FOO: z.string(),
BAZ: z.coerce.boolean(),
});
// server.mjs
serverSchema.parse({
...process.env,
...destructured
});
env.BAZ Will still work outside of next middleware
I get what you mean, @juliusmarminge. However, I think like this it could be misleading. What we could do, is using the Like:
Also: We would be facing some issues with the validation on the middleware-side. When we only add the middleware environment variables one-by-one, it would be giving us schema validation errors, when using on the middleware (because – in your case – Edit: Just saw the |
Fair points. I didnt think of that. I just want to make sure we provide as good DX as possible as many will think its annoying to do this many steps "just to get rid of |
What Btw: Do you know, why the build is failing with a wrong import (working for me locally). |
So I guess where I'm going is if I need to do too much work to get it running in the first place, maybe I'd be fine with using // in some edge function, e.g. 'src/middleware.ts'
const baz1 = process.env.BAZ;
// ^? -> string | undefined
const baz2 = process.env.BAZ!;
//. ^? -> string Either would be fine since the variable have been validated to be present during build time. Maybe I'm drifting here and this isn't a problem for others? I just wanna make sure we don't make it too much work to get environment variables to work or else people might just nuke it all and use
You haven't defined the |
I personally wouldn't want to use the non-null assertion throughout my application. Also for the purpose of the env validation, that t3 offers, I am sure there are use-cases, which would be awesome to have default's for. So, just using |
Yea all valid points - curious how many apps use the |
I think this issue is giving us the reason.
I think this is due to the nature of the |
What's the plan to go for? Asking Next.js team first and implementing the PR for now? Or are we not wanting to implement the PR as is? |
I think this is the best approach even though I'm not a fan of the extra step - but that seems to be out of our hands unfortunately... Go ahead and fix this up and we can ship it if no-one else has any objections? @c-ehrlich @nexxeln |
Sounds good to me |
OK, guys.
|
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.
👍👍
Seems like you've disabled maintainers edit priviledges so i cant update your branch |
Bit late but I agree with this |
How am I able to enable this? This is a repository from my company, so could be that this is the the case company-wide? Couldn't find a way to enable this? -- Edit: updated manually |
Should be on the right side where you request reviews etc |
Closes #
✅ Checklist
Changelog
💯