Skip to content

Fix: prevent RangeError: Invalid time value in date filter serialization#719

Open
paanSinghCoder wants to merge 1 commit intomainfrom
fix/calendar-handle-error
Open

Fix: prevent RangeError: Invalid time value in date filter serialization#719
paanSinghCoder wants to merge 1 commit intomainfrom
fix/calendar-handle-error

Conversation

@paanSinghCoder
Copy link
Contributor

@paanSinghCoder paanSinghCoder commented Mar 23, 2026

Description

Problem
When using the DataTable date filter (e.g. "Created On"), opening the date picker and clicking outside could crash the page with RangeError: Invalid time value from Date.toISOString().

Root cause
dayjs.isValid() and Date.toISOString() can disagree: dayjs may treat a value as valid even when the underlying Date is outside ECMAScript’s representable range or otherwise invalid, causing toISOString() to throw.

Solution
Wrap dateValue.toISOString() in a try/catch in handleStringBasedTypes (filter-operations). On failure, use an empty string instead of letting the error propagate.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor (no functional changes, no bug fixes just code improvements)
  • Chore (changes to the build process or auxiliary tools and libraries such as documentation generation)
  • Style (changes that do not affect the meaning of the code (white-space, formatting, etc))
  • Test (adding missing tests or correcting existing tests)
  • Improvement (Improvements to existing code)
  • Other (please specify)

How Has This Been Tested?

[Describe the tests that you ran to verify your changes]

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (.mdx files)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works

Screenshots (if appropriate):

[Add screenshots here]

Related Issues

[Link any related issues here using #issue-number]

Summary by CodeRabbit

  • Bug Fixes
    • Improved date filter reliability in data tables with enhanced error handling and validation. Invalid dates and edge cases are now handled gracefully, preventing conversion errors.

@vercel
Copy link

vercel bot commented Mar 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
apsara Ready Ready Preview, Comment Mar 23, 2026 11:13am

@paanSinghCoder paanSinghCoder requested a review from rsbh March 23, 2026 11:13
@paanSinghCoder paanSinghCoder self-assigned this Mar 23, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 23, 2026

📝 Walkthrough

Walkthrough

The change enhances date value handling in the filter operations utility by adding explicit validity checking and exception handling for date-to-ISO string conversion. Rather than using inline conditionals, the code now validates the dayjs instance before conversion and catches potential runtime errors.

Changes

Cohort / File(s) Summary
Date Filter Error Handling
packages/raystack/components/data-table/utils/filter-operations.tsx
Enhanced handleStringBasedTypes for FilterType.date with guarded dayjs() validation and try-catch exception handling around toISOString() conversion to ensure robustness against invalid date values.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • rsbh
  • rohanchkrabrty
  • singh-pk

Poem

🐰 A date once caused trouble with strings,
But guards and exceptions bring wings!
With dayjs we dance,
Catching errors in trance,
Safe conversions are what validation brings! 📅✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: preventing a RangeError in date filter serialization.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/calendar-handle-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/raystack/components/data-table/utils/filter-operations.tsx (1)

170-182: Please add a regression test for this exact failure mode.

Add a unit test around getFilterValue/handleStringBasedTypes for FilterType.date where ISO serialization throws, and assert stringValue becomes '' instead of throwing.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/raystack/components/data-table/utils/filter-operations.tsx` around
lines 170 - 182, Add a regression unit test for
getFilterValue/handleStringBasedTypes covering FilterType.date that simulates
dayjs(value).toISOString() throwing and asserts the returned object has
stringValue === ''. In the test, mock or stub the dayjs instance used by
handleStringBasedTypes (or the toISOString method) to throw when called for a
date filter, then call getFilterValue (or handleStringBasedTypes directly) with
FilterType.date and the test value, and assert the function returns { value,
stringValue: '' } and does not propagate an error.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/raystack/components/data-table/utils/filter-operations.tsx`:
- Around line 170-182: Add a regression unit test for
getFilterValue/handleStringBasedTypes covering FilterType.date that simulates
dayjs(value).toISOString() throwing and asserts the returned object has
stringValue === ''. In the test, mock or stub the dayjs instance used by
handleStringBasedTypes (or the toISOString method) to throw when called for a
date filter, then call getFilterValue (or handleStringBasedTypes directly) with
FilterType.date and the test value, and assert the function returns { value,
stringValue: '' } and does not propagate an error.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 06dd4e0a-e1e5-429f-bcf8-b3f4630d27a7

📥 Commits

Reviewing files that changed from the base of the PR and between 9d4cf92 and 7290cf1.

📒 Files selected for processing (1)
  • packages/raystack/components/data-table/utils/filter-operations.tsx

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.

1 participant