fix(webapp): conditionally load Stripe only when publishable key exists#5728
fix(webapp): conditionally load Stripe only when publishable key exists#5728cyphercodes wants to merge 2 commits intoNangoHQ:masterfrom
Conversation
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
There was a problem hiding this comment.
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
packages/webapp/src/utils/stripe.ts
Outdated
|
|
||
| const stripePublishableKey = globalEnv.publicStripeKey; | ||
| export const stripePromise = loadStripe(stripePublishableKey); | ||
| export const stripePromise = stripePublishableKey ? loadStripe(stripePublishableKey) : null; |
There was a problem hiding this comment.
[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.
| 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|
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. |
|
Fixed, thanks for the review! |
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
packages/webapp/src/utils/stripe.tsto conditionally callloadStripe()only whenpublicStripeKeyis truthynullinstead of callingloadStripe("")when the key is emptyTesting
IntegrationError: Please call Stripe() with your publishable key. You used an empty string.errorThis PR updates Stripe initialization to avoid calling
loadStripe()with an empty publishable key. WhenglobalEnv.publicStripeKeyis falsy,stripePromisenow resolves tonull, preventing the self-hosted dashboard crash caused by Stripe's empty-key error.This summary was automatically generated by @propel-code-bot