fix(billing): safely initialize Stripe only when publishable key is present (#5344) - #5442
Open
fliptrigga13 wants to merge 1 commit into
Open
fliptrigga13 wants to merge 1 commit into
fliptrigga13 wants to merge 1 commit into
Conversation
Comment on lines
+4
to
+8
| const createStripeLoader = (loadStripeMock: (key: string) => Promise<any>) => { | ||
| return (publishableKey?: string) => { | ||
| return publishableKey ? loadStripeMock(publishableKey) : null; | ||
| }; | ||
| }; |
Contributor
There was a problem hiding this comment.
Tests duplicate production logic
These tests recreate the Stripe initialization and checkout guards locally instead of importing or exercising either changed production module. Reverting or breaking the guards in PlanStep or ShowBilling would therefore leave all three tests passing, so CI does not protect against this dashboard crash returning. Extract the initialization behavior into an imported helper or test the production modules with loadStripe mocked. The checkout handler at lines 53–60 has the same problem.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this PR about?
Fixes #5344
Problem
On self-hosted installations,
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEYis not configured (as perapps/dokploy/.env.exampleandDockerfile, where Stripe is cloud-only).However,
PlanStepandShowBillingcalledloadStripeat module scope:Because the onboarding wizard (
apps/dokploy/components/dashboard/onboarding/onboarding-wizard.tsx) is statically imported byapps/dokploy/pages/dashboard/home.tsx, loading the dashboard immediately executesloadStripe(undefined).Stripe's SDK rejects this at module initialization time with:
This crashed the dashboard on login for every self-hosted instance.
Solution
stripePromisesafely at module scope:stripePromiseisnullandloadStripeis never invoked withundefined.PlanStepandShowBillingso attempting checkout without a configured Stripe key safely alerts via toast notification instead of throwing unhandled rejections.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEYis present,loadStripeexecutes normally.Checklist
canarybranch.apps/dokploy/__test__/billing/stripe-initialization.test.ts(3/3 passing tests).Issues related
Fixes #5344
The production fix appears safe to merge, with a non-blocking gap in regression-test effectiveness.
Summary
Reviews (1) · Last reviewed commit: "fix(billing): safely initialize Stripe o..."