fix(trials): Fix missing and negative day-count in product trial alerts and tags#119118
Open
souredoutlook wants to merge 2 commits into
Open
fix(trials): Fix missing and negative day-count in product trial alerts and tags#119118souredoutlook wants to merge 2 commits into
souredoutlook wants to merge 2 commits into
Conversation
…oduct trial expires Co-Authored-By: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
When daysLeft === 0 (trial ends today), ProductTrialAlert fell through all conditional branches without matching any, leaving alertHeader and alertText null and rendering an empty invisible alert. Include daysLeft === 0 in the 0-7 days remaining branch by changing the condition from daysLeft > 0 to daysLeft >= 0. Co-Authored-By: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
| showTrialEnded = false, | ||
| }: ProductTrialTagProps) { | ||
| const now = moment(); | ||
| const daysLeft = -1 * getDaysSinceDate(trial.endDate ?? ''); |
Contributor
There was a problem hiding this comment.
Bug: When trial.endDate is null or undefined, the component incorrectly calculates the days remaining as NaN and renders "NaN days left" to the user.
Severity: MEDIUM
Suggested Fix
Add a guard clause at the beginning of the component to handle cases where trial.endDate is null or undefined. If endDate is not present, return null early to prevent the getDaysSinceDate calculation from executing with invalid input and producing NaN.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: static/gsApp/components/productTrial/productTrialTag.tsx#L22
Potential issue: The `ProductTrial` type definition allows the `endDate` field to be
optional. When `trial.endDate` is `null` or `undefined`, the code passes an empty string
to `getDaysSinceDate` due to the `?? ''` nullish coalescing operator. The
`getDaysSinceDate` function, when called with an empty string, uses `moment('')` which
results in an invalid date, causing the function to return `NaN`. Consequently, the
`daysLeft` variable becomes `NaN`. All subsequent conditional checks on `daysLeft`
(e.g., `daysLeft < 0`) evaluate to false, leading the component to render the
user-facing text "NaN days left". This bug is introduced by the pull request's
refactoring, which moves the calculation before the necessary safety checks.
Also affects:
static/app/utils/getDaysSinceDate.tsxstatic/gsApp/types/index.tsx:268static/gsApp/components/productTrial/productTrialAlert.tsx:57
Did we get this right? 👍 / 👎 to inform future reviews.
armenzg
approved these changes
Jul 7, 2026
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.
Two related bugs in the logging trial UI when a trial's
endDateis today or yesterday.Bug 1 —
ProductTrialTagshows "-1 days left" instead of "Trial ended"When
endDatehas a late-day time component (e.g.2026-07-05T23:00:00), the old "Trial ended" guard used an exact timestamp check:moment(endDate).add(1, 'days').isBefore(now). IfendDate + 1 dayhasn't passed in clock time, the guard doesn't fire. ButgetDaysSinceDatenormalizes to start-of-day before diffing, so it returns1for a trial that ended yesterday regardless of time — producingdaysLeft = -1and rendering "-1 days left".Fix: compute
daysLeftfirst viagetDaysSinceDate(the single source of truth), then branch ondaysLeft < 0for the "Trial ended" state.Bug 2 —
ProductTrialAlertrenders nothing whendaysLeft === 0When the trial ends today (
daysLeft === 0andtrial.isStarted === true), none of the four conditional branches inProductTrialAlertmatched:daysLeft >= 0 && !isStarted— false (trial is started)daysLeft > 7— falsedaysLeft > 0 && daysLeft <= 7— false (0 > 0is false)daysLeft < 0— falseSo
alertHeader,alertText,alertButtonall stayed null and the alert rendered invisible — no notice shown at all.Fix: change
daysLeft > 0 && daysLeft <= 7todaysLeft >= 0 && daysLeft <= 7to include the last-day case in the 0–7 days remaining branch.