@@ -48,6 +48,7 @@ import { vercelAppInstallPath, v3ProjectSettingsIntegrationsPath, githubAppInsta
4848import type { loader } from "~/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.vercel" ;
4949import { useEffect , useState , useCallback , useRef } from "react" ;
5050import { usePostHogTracking } from "~/hooks/usePostHog" ;
51+ import { TextLink } from "../primitives/TextLink" ;
5152
5253function safeRedirectUrl ( url : string ) : string | null {
5354 try {
@@ -224,9 +225,10 @@ export function VercelOnboardingModal({
224225 ( ) => availableEnvSlugsForOnboardingBuildSettings
225226 ) ;
226227
227- // Sync pullEnvVarsBeforeBuild and discoverEnvVars when hasStagingEnvironment becomes true (once)
228+ // Sync pullEnvVarsBeforeBuild and discoverEnvVars when hasStagingEnvironment becomes true
229+ // AND a custom Vercel environment is mapped (once)
228230 useEffect ( ( ) => {
229- if ( hasStagingEnvironment && ! hasSyncedStagingRef . current ) {
231+ if ( hasStagingEnvironment && vercelStagingEnvironment && ! hasSyncedStagingRef . current ) {
230232 hasSyncedStagingRef . current = true ;
231233 setPullEnvVarsBeforeBuild ( ( prev ) => {
232234 if ( ! prev . includes ( "stg" ) ) {
@@ -241,7 +243,15 @@ export function VercelOnboardingModal({
241243 return prev ;
242244 } ) ;
243245 }
244- } , [ hasStagingEnvironment ] ) ;
246+ } , [ hasStagingEnvironment , vercelStagingEnvironment ] ) ;
247+
248+ // Strip "stg" from build settings when the staging environment mapping is cleared
249+ useEffect ( ( ) => {
250+ if ( ! vercelStagingEnvironment ) {
251+ setPullEnvVarsBeforeBuild ( ( prev ) => prev . filter ( ( s ) => s !== "stg" ) ) ;
252+ setDiscoverEnvVars ( ( prev ) => prev . filter ( ( s ) => s !== "stg" ) ) ;
253+ }
254+ } , [ vercelStagingEnvironment ] ) ;
245255
246256 // Sync pullEnvVarsBeforeBuild and discoverEnvVars when hasPreviewEnvironment becomes true (once)
247257 useEffect ( ( ) => {
@@ -670,6 +680,11 @@ export function VercelOnboardingModal({
670680 const showBuildSettings = state === "build-settings" ;
671681 const showGitHubConnection = state === "github-connection" ;
672682
683+ const disabledEnvSlugsForBuildSettings =
684+ hasStagingEnvironment && ! vercelStagingEnvironment
685+ ? ( { stg : "Map a custom Vercel environment to Staging to enable this" } as Partial < Record < EnvSlug , string > > )
686+ : undefined ;
687+
673688 return (
674689 < Dialog open = { isOpen } onOpenChange = { ( open ) => {
675690 if ( ! open && ! fromMarketplaceContext ) {
@@ -731,7 +746,7 @@ export function VercelOnboardingModal({
731746 ) }
732747
733748 < Hint >
734- Once connected, your < code className = "text-xs" > TRIGGER_SECRET_KEY</ code > will be
749+ Once connected, your < code className = "text-xs rounded bg-charcoal-700 px-1 py-0.5 text-text-bright " > TRIGGER_SECRET_KEY</ code > will be
735750 automatically synced to Vercel for each environment.
736751 </ Hint >
737752
@@ -775,6 +790,10 @@ export function VercelOnboardingModal({
775790 < Paragraph className = "text-sm" >
776791 Select which custom Vercel environment should map to Trigger.dev's Staging
777792 environment. Production and Preview environments are mapped automatically.
793+ If you skip this step, the{ " " }
794+ < code className = "rounded bg-charcoal-700 px-1 py-0.5 text-text-bright" > TRIGGER_SECRET_KEY</ code > { " " }
795+ will not be installed for the staging environment in Vercel. You can configure this later in
796+ project settings.
778797 </ Paragraph >
779798
780799 < Select
@@ -800,15 +819,6 @@ export function VercelOnboardingModal({
800819 ) ) }
801820 </ Select >
802821
803- < Callout variant = "info" >
804- < p className = "text-xs" >
805- If you skip this step, the{ " " }
806- < code className = "rounded bg-charcoal-700 px-1 py-0.5 text-text-bright" > TRIGGER_SECRET_KEY</ code > { " " }
807- will not be installed for the staging environment in Vercel. You can configure this later in
808- project settings.
809- </ p >
810- </ Callout >
811-
812822 < Paragraph className = "text-xs text-text-dimmed" >
813823 Make sure the staging branch in your Vercel project's Git settings matches the staging branch
814824 configured in your GitHub integration.
@@ -845,25 +855,13 @@ export function VercelOnboardingModal({
845855
846856 { showEnvVarSync && (
847857 < div className = "flex flex-col gap-4" >
848- < Header3 > Pull Environment Variables</ Header3 >
849- < Paragraph className = "text-sm" >
850- Select which environment variables to pull from Vercel now. This is a one-time pull.
851- Later on environment variables can be pulled before each build.
852- </ Paragraph >
853-
854- < div className = "flex gap-4 text-sm" >
855- < div className = "rounded border bg-charcoal-750 px-3 py-2" >
856- < span className = "font-medium text-text-bright" > { syncableEnvVars . length } </ span >
857- < span className = "text-text-dimmed" > can be pulled</ span >
858- </ div >
859- { secretEnvVars . length > 0 && (
860- < div className = "rounded border bg-charcoal-750 px-3 py-2" >
861- < span className = "font-medium text-amber-400" > { secretEnvVars . length } </ span >
862- < span className = "text-text-dimmed" > secret (cannot pull)</ span >
863- </ div >
864- ) }
858+ < div className = "flex flex-col gap-1" >
859+ < Header3 > Pull Environment Variables</ Header3 >
860+ < Paragraph className = "text-sm" >
861+ Choose which environment variables to import from Vercel. This runs as a one time pull to prefill your project with the variables it needs. You’ll be able to pull again later, or enable automatic syncing before each build if you prefer.
862+ If you are using Supabase or Neon branching, < TextLink href = "https://trigger.dev/docs/vercel-integration#supabase-and-neon-database-branching" target = "_blank" rel = "noopener noreferrer" > read the docs</ TextLink > for the recommended setup.
863+ </ Paragraph >
865864 </ div >
866-
867865 < div className = "flex items-center justify-between rounded border bg-charcoal-800 p-3" >
868866 < div >
869867 < Label > Pull all environment variables now</ Label >
@@ -1052,6 +1050,7 @@ export function VercelOnboardingModal({
10521050 onDiscoverEnvVarsChange = { setDiscoverEnvVars }
10531051 atomicBuilds = { atomicBuilds }
10541052 onAtomicBuildsChange = { setAtomicBuilds }
1053+ disabledEnvSlugs = { disabledEnvSlugsForBuildSettings }
10551054 />
10561055
10571056 < FormButtons
0 commit comments