Skip to content

Conversation

@billyvg
Copy link
Member

@billyvg billyvg commented Oct 30, 2025

This fixes the following console.warn that we are getting in prod:

 Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:

We were passing a deprecated date format to getDaysSinceDate(): moment().utc().toDate().toDateString(). I have replaced it with an ISO date string.

This fixes the following console.warn that we are getting in prod:

```
 Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:
```

We were passing a deprecated date format to `getDaysSinceDate()`: `moment().utc().toDate().toDateString()`. I have replaced it with an ISO date string.
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Oct 30, 2025
@billyvg billyvg marked this pull request as ready for review October 30, 2025 17:51
@billyvg
Copy link
Member Author

billyvg commented Oct 30, 2025

@sentry review

Comment on lines 210 to 216
organization,
daysToSnooze:
-1 *
getDaysSinceDate(
subscription?.onDemandPeriodEnd ?? moment().utc().toDate().toDateString()
),
getDaysSinceDate(subscription?.onDemandPeriodEnd ?? moment().utc().toISOString()),
isDismissed: isSnoozedForCurrentPeriod,
options: {
enabled: promptsToCheck.length > 0,
Copy link

Choose a reason for hiding this comment

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

Bug: localStorage.setItem at navBillingStatus.tsx:289 writes a deprecated date format, causing getDaysSinceDate to receive an invalid input.
Severity: HIGH | Confidence: 1.00

🔍 Detailed Analysis

The code at navBillingStatus.tsx:289 stores a date in localStorage using moment().utc().toDate().toDateString(), which generates a deprecated date format. This value is subsequently retrieved and passed to getDaysSinceDate() at line 277. Despite a fix for another instance, this specific localStorage write was not updated, causing getDaysSinceDate() to consistently receive the deprecated format and trigger deprecation warnings.

💡 Suggested Fix

Update the localStorage.setItem call at navBillingStatus.tsx:289 to store the date in ISO format using moment().utc().toISOString().

🤖 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/navBillingStatus.tsx#L210-L216

Potential issue: The code at `navBillingStatus.tsx:289` stores a date in `localStorage`
using `moment().utc().toDate().toDateString()`, which generates a deprecated date
format. This value is subsequently retrieved and passed to `getDaysSinceDate()` at line
277. Despite a fix for another instance, this specific `localStorage` write was not
updated, causing `getDaysSinceDate()` to consistently receive the deprecated format and
trigger deprecation warnings.

Did we get this right? 👍 / 👎 to inform future reviews.

Comment on lines +213 to 215
getDaysSinceDate(subscription?.onDemandPeriodEnd ?? moment().utc().toISOString()),
isDismissed: isSnoozedForCurrentPeriod,
options: {
Copy link

Choose a reason for hiding this comment

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

The fallback parameter passed to getDaysSinceDate has been changed to use ISO format (toISOString()), which is good practice and is now tested. However, there is an inconsistency: on line 245, the date is still being stored in localStorage using the deprecated toDateString() format ('Mon Jun 06 2022'). This means when lastShownDate is retrieved from localStorage and passed to getDaysSinceDate() on line 231, it will be in the old format. While getDaysSinceDate() appears to support both formats (as verified by the new tests), it would be more consistent and future-proof to also update line 245 to store dates in ISO format using moment().utc().toISOString() instead of moment().utc().toDate().toDateString().
Severity: MEDIUM

🤖 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/navBillingStatus.tsx#L213-L215

Potential issue: The fallback parameter passed to getDaysSinceDate has been changed to
use ISO format (toISOString()), which is good practice and is now tested. However, there
is an inconsistency: on line 245, the date is still being stored in localStorage using
the deprecated toDateString() format ('Mon Jun 06 2022'). This means when lastShownDate
is retrieved from localStorage and passed to getDaysSinceDate() on line 231, it will be
in the old format. While getDaysSinceDate() appears to support both formats (as verified
by the new tests), it would be more consistent and future-proof to also update line 245
to store dates in ISO format using moment().utc().toISOString() instead of
moment().utc().toDate().toDateString().

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the localStorage to use ISO string as well. When reading from local storage, we parse the date with moment(), so it will remain compatible with both formats.

@codecov
Copy link

codecov bot commented Oct 30, 2025

❌ 4 Tests Failed:

Tests completed Failed Passed Skipped
12298 4 12294 10
View the top 3 failed test(s) by shortest run time
PrimaryNavigationQuotaExceeded should auto open the alert when the last shown date is before the current usage cycle started
Stack Traces | 0.057s run time
Error: expect(received).toBe(expected) // Object.is equality

Expected: "Mon Jun 06 2022"
Received: "2022-06-06T05:09:33.000Z"
    at toBe (.../gsApp/components/navBillingStatus.spec.tsx:100:7)
    at Object.assertLocalStorageStateAfterAutoOpen (.../gsApp/components/navBillingStatus.spec.tsx:419:5)
PrimaryNavigationQuotaExceeded should auto open the alert when more than a day has passed
Stack Traces | 0.069s run time
Error: expect(received).toBe(expected) // Object.is equality

Expected: "Mon Jun 06 2022"
Received: "2022-06-06T05:09:33.000Z"
    at toBe (.../gsApp/components/navBillingStatus.spec.tsx:100:7)
    at Object.assertLocalStorageStateAfterAutoOpen (.../gsApp/components/navBillingStatus.spec.tsx:409:5)
PrimaryNavigationQuotaExceeded should auto open the alert when categories have changed
Stack Traces | 0.086s run time
Error: expect(received).toBe(expected) // Object.is equality

Expected: "Mon Jun 06 2022"
Received: "2022-06-06T05:09:33.000Z"
    at toBe (.../gsApp/components/navBillingStatus.spec.tsx:100:7)
    at Object.assertLocalStorageStateAfterAutoOpen (.../gsApp/components/navBillingStatus.spec.tsx:399:5)
PrimaryNavigationQuotaExceeded should auto open based on localStorage
Stack Traces | 0.094s run time
Error: expect(received).toBe(expected) // Object.is equality

Expected: "Mon Jun 06 2022"
Received: "2022-06-06T05:09:33.000Z"
    at toBe (.../gsApp/components/navBillingStatus.spec.tsx:100:7)
    at Object.assertLocalStorageStateAfterAutoOpen (.../gsApp/components/navBillingStatus.spec.tsx:326:5)

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Copy link
Member

@isabellaenriquez isabellaenriquez left a comment

Choose a reason for hiding this comment

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

thanks!

@billyvg billyvg merged commit 9c1576d into master Oct 30, 2025
47 checks passed
@billyvg billyvg deleted the billy/fix-moment-deprecation-warning branch October 30, 2025 20:02
shashjar pushed a commit that referenced this pull request Nov 4, 2025
This fixes the following console.warn that we are getting in prod:

```
 Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:
```

We were passing a deprecated date format to `getDaysSinceDate()`:
`moment().utc().toDate().toDateString()`. I have replaced it with an ISO
date string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants