Skip to content

fix(webapp): conditionally load Stripe only when publishable key exists#5728

Open
cyphercodes wants to merge 2 commits intoNangoHQ:masterfrom
cyphercodes:fix-stripe-selfhosted
Open

fix(webapp): conditionally load Stripe only when publishable key exists#5728
cyphercodes wants to merge 2 commits intoNangoHQ:masterfrom
cyphercodes:fix-stripe-selfhosted

Conversation

@cyphercodes
Copy link
Copy Markdown

@cyphercodes cyphercodes commented Mar 27, 2026

Problem

The Nango dashboard renders a completely blank/black screen on self-hosted instances because stripe.js attempts to initialize with an empty string, throwing an unhandled error that kills the entire React app.

Fixes #5640

Changes

  • Modified packages/webapp/src/utils/stripe.ts to conditionally call loadStripe() only when publicStripeKey is truthy
  • Returns null instead of calling loadStripe("") when the key is empty

Testing

  • This fix prevents the IntegrationError: Please call Stripe() with your publishable key. You used an empty string. error
  • Self-hosted instances will now load the dashboard properly
  • Cloud instances with a valid Stripe key continue to work normally

This PR updates Stripe initialization to avoid calling loadStripe() with an empty publishable key. When globalEnv.publicStripeKey is falsy, stripePromise now resolves to null, preventing the self-hosted dashboard crash caused by Stripe's empty-key error.


This summary was automatically generated by @propel-code-bot

Prevent dashboard crash on self-hosted instances where publicStripeKey
is empty. The Stripe.js library throws an error when initialized with
an empty string, causing a blank screen for all self-hosted users.

Fixes NangoHQ#5640
Copy link
Copy Markdown
Contributor

@propel-code-bot propel-code-bot bot left a comment

Choose a reason for hiding this comment

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

Suggested change to keep stripePromise consistently a Promise to avoid null runtime errors.

Status: Changes Suggested | Risk: Medium

Issues Identified & Suggestions
  • Ensure stripePromise is always a Promise to avoid null usage: packages/webapp/src/utils/stripe.ts
Review Details

📁 1 files reviewed | 💬 1 comments

Instruction Files
└── .claude/
    ├── agents/
    │   └── nango-docs-migrator.md
    └── skills

👍 / 👎 individual comments to help improve reviews for you


const stripePublishableKey = globalEnv.publicStripeKey;
export const stripePromise = loadStripe(stripePublishableKey);
export const stripePromise = stripePublishableKey ? loadStripe(stripePublishableKey) : null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

[Reliability] The stripePromise variable can now be null directly if stripePublishableKey is falsy. However, loadStripe() itself always returns a Promise<Stripe | null>. This change means stripePromise's type effectively changes from Promise<Stripe | null> to Promise<Stripe | null> | null. Any code consuming stripePromise that expects it to always be a Promise (e.g., by calling .then() or awaiting it) will now encounter a runtime TypeError: Cannot read properties of null (reading 'then') if the key is not present.

Suggested change
export const stripePromise = stripePublishableKey ? loadStripe(stripePublishableKey) : null;
export const stripePromise = stripePublishableKey ? loadStripe(stripePublishableKey) : Promise.resolve(null);
Context for Agents
[**Bug**] The `stripePromise` variable can now be `null` directly if `stripePublishableKey` is falsy. However, `loadStripe()` itself always returns a `Promise<Stripe | null>`. This change means `stripePromise`'s type effectively changes from `Promise<Stripe | null>` to `Promise<Stripe | null> | null`. Any code consuming `stripePromise` that expects it to always be a Promise (e.g., by calling `.then()` or `await`ing it) will now encounter a runtime `TypeError: Cannot read properties of null (reading 'then')` if the key is not present.

```suggestion
export const stripePromise = stripePublishableKey ? loadStripe(stripePublishableKey) : Promise.resolve(null);
```

File: packages/webapp/src/utils/stripe.ts
Line: 6

@cyphercodes
Copy link
Copy Markdown
Author

Updated the fix to keep astripePromisea consistently as a Promise to avoid null runtime errors. Changed the fallback from anulla to aPromise.resolve(null)a as suggested by propel-code-bot.

Copy link
Copy Markdown
Contributor

@propel-code-bot propel-code-bot bot left a comment

Choose a reason for hiding this comment

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

Review found no issues; changes appear appropriate and well-scoped.

Status: No Issues Found | Risk: Low

Review Details

📁 1 files reviewed | 💬 0 comments

Instruction Files
└── .claude/
    ├── agents/
    │   └── nango-docs-migrator.md
    └── skills

@cyphercodes
Copy link
Copy Markdown
Author

Fixed, thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

publicStripeKey: "" crash in env.js for self-hosted instances.

1 participant