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(tanstack-start): Fix environment variable loading in runtime contexts #4743

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

octoper
Copy link
Member

@octoper octoper commented Dec 10, 2024

Description

The PR fixes an issue where environment variables are accessed global contexts, which doesn't work in runtimes like Cloudflare that only make them available during the request lifecycle.

Nitro environment variables guideline

Resolves ECO-288 and ECO-274

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Copy link

changeset-bot bot commented Dec 10, 2024

🦋 Changeset detected

Latest commit: 6685212

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clerk/tanstack-start Patch

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

Copy link

vercel bot commented Dec 10, 2024

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

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 15, 2025 0:05am

@octoper
Copy link
Member Author

octoper commented Dec 10, 2024

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @octoper - the snapshot version command generated the following package versions:

Package Version
@clerk/astro 2.0.1-snapshot.v20241210001110
@clerk/backend 1.20.3-snapshot.v20241210001110
@clerk/chrome-extension 2.0.9-snapshot.v20241210001110
@clerk/clerk-js 5.40.3-snapshot.v20241210001110
@clerk/elements 0.21.4-snapshot.v20241210001110
@clerk/clerk-expo 2.4.5-snapshot.v20241210001110
@clerk/expo-passkeys 0.0.17-snapshot.v20241210001110
@clerk/express 1.3.26-snapshot.v20241210001110
@clerk/fastify 2.0.28-snapshot.v20241210001110
@clerk/localizations 3.8.2-snapshot.v20241210001110
@clerk/nextjs 6.8.3-snapshot.v20241210001110
@clerk/nuxt 0.0.13-snapshot.v20241210001110
@clerk/clerk-react 5.19.3-snapshot.v20241210001110
@clerk/react-router 0.0.2-snapshot.v20241210001110
@clerk/remix 4.3.6-snapshot.v20241210001110
@clerk/clerk-sdk-node 5.0.77-snapshot.v20241210001110
@clerk/shared 2.19.4-snapshot.v20241210001110
@clerk/tanstack-start 0.7.0-snapshot.v20241210001110
@clerk/testing 1.3.38-snapshot.v20241210001110
@clerk/themes 2.1.55-snapshot.v20241210001110
@clerk/types 4.39.2-snapshot.v20241210001110
@clerk/ui 0.2.4-snapshot.v20241210001110
@clerk/vue 0.0.17-snapshot.v20241210001110

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/astro

npm i @clerk/astro@2.0.1-snapshot.v20241210001110 --save-exact

@clerk/backend

npm i @clerk/backend@1.20.3-snapshot.v20241210001110 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@2.0.9-snapshot.v20241210001110 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.40.3-snapshot.v20241210001110 --save-exact

@clerk/elements

npm i @clerk/elements@0.21.4-snapshot.v20241210001110 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@2.4.5-snapshot.v20241210001110 --save-exact

@clerk/expo-passkeys

npm i @clerk/expo-passkeys@0.0.17-snapshot.v20241210001110 --save-exact

@clerk/express

npm i @clerk/express@1.3.26-snapshot.v20241210001110 --save-exact

@clerk/fastify

npm i @clerk/fastify@2.0.28-snapshot.v20241210001110 --save-exact

@clerk/localizations

npm i @clerk/localizations@3.8.2-snapshot.v20241210001110 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@6.8.3-snapshot.v20241210001110 --save-exact

@clerk/nuxt

npm i @clerk/nuxt@0.0.13-snapshot.v20241210001110 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.19.3-snapshot.v20241210001110 --save-exact

@clerk/react-router

npm i @clerk/react-router@0.0.2-snapshot.v20241210001110 --save-exact

@clerk/remix

npm i @clerk/remix@4.3.6-snapshot.v20241210001110 --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@5.0.77-snapshot.v20241210001110 --save-exact

@clerk/shared

npm i @clerk/shared@2.19.4-snapshot.v20241210001110 --save-exact

@clerk/tanstack-start

npm i @clerk/tanstack-start@0.7.0-snapshot.v20241210001110 --save-exact

@clerk/testing

npm i @clerk/testing@1.3.38-snapshot.v20241210001110 --save-exact

@clerk/themes

npm i @clerk/themes@2.1.55-snapshot.v20241210001110 --save-exact

@clerk/types

npm i @clerk/types@4.39.2-snapshot.v20241210001110 --save-exact

@clerk/ui

npm i @clerk/ui@0.2.4-snapshot.v20241210001110 --save-exact

@clerk/vue

npm i @clerk/vue@0.0.17-snapshot.v20241210001110 --save-exact

@clerk clerk deleted a comment from clerk-cookie Jan 14, 2025
@wobsoriano wobsoriano changed the title fix(tanstack-start): Fix ENV variable loading fix(tanstack-start): Improve environment variable resolution for runtime context Jan 14, 2025
@wobsoriano
Copy link
Member

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @wobsoriano - the snapshot version command generated the following package versions:

Package Version
@clerk/astro 2.1.8-snapshot.v20250115000107
@clerk/backend 1.22.1-snapshot.v20250115000107
@clerk/chrome-extension 2.1.12-snapshot.v20250115000107
@clerk/clerk-js 5.44.1-snapshot.v20250115000107
@clerk/clerk-expo 2.6.11-snapshot.v20250115000107
@clerk/express 1.3.35-snapshot.v20250115000107
@clerk/fastify 2.1.8-snapshot.v20250115000107
@clerk/nextjs 6.9.11-snapshot.v20250115000107
@clerk/nuxt 1.0.4-snapshot.v20250115000107
@clerk/react-router 0.1.9-snapshot.v20250115000107
@clerk/remix 4.4.10-snapshot.v20250115000107
@clerk/tanstack-start 0.8.9-snapshot.v20250115000107
@clerk/testing 1.4.8-snapshot.v20250115000107
@clerk/vue 1.0.3-snapshot.v20250115000107

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/astro

npm i @clerk/astro@2.1.8-snapshot.v20250115000107 --save-exact

@clerk/backend

npm i @clerk/backend@1.22.1-snapshot.v20250115000107 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@2.1.12-snapshot.v20250115000107 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.44.1-snapshot.v20250115000107 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@2.6.11-snapshot.v20250115000107 --save-exact

@clerk/express

npm i @clerk/express@1.3.35-snapshot.v20250115000107 --save-exact

@clerk/fastify

npm i @clerk/fastify@2.1.8-snapshot.v20250115000107 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@6.9.11-snapshot.v20250115000107 --save-exact

@clerk/nuxt

npm i @clerk/nuxt@1.0.4-snapshot.v20250115000107 --save-exact

@clerk/react-router

npm i @clerk/react-router@0.1.9-snapshot.v20250115000107 --save-exact

@clerk/remix

npm i @clerk/remix@4.4.10-snapshot.v20250115000107 --save-exact

@clerk/tanstack-start

npm i @clerk/tanstack-start@0.8.9-snapshot.v20250115000107 --save-exact

@clerk/testing

npm i @clerk/testing@1.4.8-snapshot.v20250115000107 --save-exact

@clerk/vue

npm i @clerk/vue@1.0.3-snapshot.v20250115000107 --save-exact

@wobsoriano wobsoriano changed the title fix(tanstack-start): Improve environment variable resolution for runtime context fix(tanstack-start): Fix environment variable resolution for runtime context Jan 15, 2025
@wobsoriano wobsoriano changed the title fix(tanstack-start): Fix environment variable resolution for runtime context fix(tanstack-start): Fix environment variable loading in runtime contexts Jan 15, 2025
Comment on lines +16 to +20
// Cloudflare context check
const cfValue = event?.context?.cloudflare?.env[name];
if (cfValue) {
return cfValue;
}
Copy link
Member

@wobsoriano wobsoriano Jan 15, 2025

Choose a reason for hiding this comment

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

Nitro injects the runtime env vars to the H3 event context. For Cloudflare, the property is event.context.cloudflare.

We pass this event object in a request lifecycle to make runtime env vars available

I answered the same question here.

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

Successfully merging this pull request may close these issues.

3 participants