Skip to content

Comments

fix: handle NaN != NaN prefetch#23910

Merged
emrysal merged 1 commit intomainfrom
dont-prefetch-next-2-months-when-2-weeks-cross
Sep 18, 2025
Merged

fix: handle NaN != NaN prefetch#23910
emrysal merged 1 commit intomainfrom
dont-prefetch-next-2-months-when-2-weeks-cross

Conversation

@hariombalhara
Copy link
Member

What does this PR do?

  • Fixes #XXXX (GitHub issue number)
  • Fixes CAL-XXXX (Linear issue number - should be visible at the bottom of the GitHub issue description)

Visual Demo (For contributors especially)

A visual demonstration is strongly recommended, for both the original and new change (video / image - any one).

Video Demo (if applicable):

  • Show screen recordings of the issue or feature.
  • Demonstrate how to reproduce the issue, the behavior before and after the change.

Image Demo (if applicable):

  • Add side-by-side screenshots of the original and updated change.
  • Highlight any significant change(s).

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • Are there environment variables that should be set?
  • What are the minimal test data to have?
  • What is expected (happy path) to have (input and output)?
  • Any other important info that could help to test that PR

Checklist

  • I haven't read the contributing guide
  • My code doesn't follow the style guidelines of this project
  • I haven't commented my code, particularly in hard-to-understand areas
  • I haven't checked if my changes generate no new warnings

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 18, 2025

Walkthrough

  • Adds derived month/date variables based on selected date and layout: _month, _monthAfterAdding1Month, _monthAfterAddingExtraDays, _monthAfterAddingExtraDaysColumnView, _isValidDate, _2WeeksAfter, _isSameMonth, _isAfter2Weeks.
  • Replaces direct dayjs().month() comparisons in prefetchNextMonth with view-specific checks:
    • WEEK_VIEW: _month !== _monthAfterAddingExtraDays
    • COLUMN_VIEW: _month !== _monthAfterAddingExtraDaysColumnView
    • MONTH_VIEW/MOBILE: uses _isValidDate, _isSameMonth, _isAfter2Weeks.
  • Updates monthCount to guard for numeric values and compare _monthAfterAdding1Month with _monthAfterAddingExtraDaysColumnView, returning 2 when different, otherwise undefined.
  • No exported/public API changes.

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description Check ❓ Inconclusive The PR description is a generic template with placeholders, unchecked task checkboxes, and demo/testing prompts but contains no concrete summary of the actual code changes or test instructions. The raw_summary and pr_objectives show specific changes to month-handling and prefetch guards, yet the description does not reflect those specifics. Because the description is very vague and does not describe the changeset, the check is inconclusive. Ask the author to update the description with a concise summary of what changed (mention key files and the behavior fixed), include the related GitHub/Linear issue IDs, provide reproduction steps and explicit testing instructions, and mark the mandatory checkboxes when completed so reviewers can validate the fix; also note any automated tests added or modified and attach a demo/screenshot if available. Once updated, re-evaluate the description check.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Title Check ✅ Passed The title "fix: handle NaN != NaN prefetch" succinctly identifies the primary bug addressed by the changeset—incorrect NaN month comparisons causing erroneous prefetch behavior. It is concise and directly related to the modifications in BookerWebWrapper.tsx that add guards and derived month calculations to avoid NaN comparisons. The phrasing is technical but specific enough for a teammate scanning history to understand the main change.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dont-prefetch-next-2-months-when-2-weeks-cross

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 18, 2025

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

No release type found in pull request title "handle NaN != NaN prefetch". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@keithwillcode keithwillcode added core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO labels Sep 18, 2025
@hariombalhara hariombalhara force-pushed the dont-prefetch-next-2-months-when-2-weeks-cross branch from 260011b to 811d4fb Compare September 18, 2025 08:54
@vercel
Copy link

vercel bot commented Sep 18, 2025

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

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Sep 18, 2025 8:57am
cal-eu Ignored Ignored Sep 18, 2025 8:57am

@hariombalhara hariombalhara force-pushed the dont-prefetch-next-2-months-when-2-weeks-cross branch from 811d4fb to 60b36f9 Compare September 18, 2025 08:55
@pull-request-size pull-request-size bot added size/S and removed size/M labels Sep 18, 2025
@hariombalhara hariombalhara force-pushed the dont-prefetch-next-2-months-when-2-weeks-cross branch from 60b36f9 to f8deee1 Compare September 18, 2025 08:56
@hariombalhara hariombalhara marked this pull request as ready for review September 18, 2025 08:58
@hariombalhara hariombalhara requested a review from a team September 18, 2025 08:58
@hariombalhara hariombalhara requested a review from a team as a code owner September 18, 2025 08:58
@dosubot dosubot bot added platform Anything related to our platform plan 🐛 bug Something isn't working labels Sep 18, 2025
Comment on lines +166 to +167
!isNaN(_monthAfterAdding1Month) &&
!isNaN(_monthAfterAddingExtraDaysColumnView) &&
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the fix. Everything else is just extracted variables

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/platform/atoms/booker/BookerWebWrapper.tsx (1)

67-67: Consider validating date format before use

The date is formatted without first checking if selectedDate is valid. While Day.js handles invalid dates gracefully, it's better to validate early.

Add validation:

-  const date = dayjs(selectedDate).format("YYYY-MM-DD");
+  const date = selectedDate && dayjs(selectedDate).isValid() 
+    ? dayjs(selectedDate).format("YYYY-MM-DD")
+    : dayjs().format("YYYY-MM-DD");
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 69a76f7 and f8deee1.

📒 Files selected for processing (1)
  • packages/platform/atoms/booker/BookerWebWrapper.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.tsx

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Always use t() for text localization in frontend code; direct text embedding should trigger a warning

Files:

  • packages/platform/atoms/booker/BookerWebWrapper.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/platform/atoms/booker/BookerWebWrapper.tsx
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • packages/platform/atoms/booker/BookerWebWrapper.tsx
🧬 Code graph analysis (1)
packages/platform/atoms/booker/BookerWebWrapper.tsx (1)
packages/embeds/embed-core/src/types.ts (1)
  • BookerLayouts (6-6)
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (3)
packages/platform/atoms/booker/BookerWebWrapper.tsx (3)

154-161: Improved month-boundary logic for prefetching

The refactored prefetch logic correctly handles NaN comparisons by explicitly checking for valid dates and using derived month calculations. This prevents the NaN !== NaN issue that would always evaluate to true.


163-170: Good NaN guards but consider edge cases

The explicit NaN checks prevent invalid comparisons. However, the condition might be overly restrictive - both values must be valid numbers for the comparison to work.

Consider handling the case where only one value is NaN:

   const monthCount =
     ((bookerLayout.layout !== BookerLayouts.WEEK_VIEW && bookerState === "selecting_time") ||
       bookerLayout.layout === BookerLayouts.COLUMN_VIEW) &&
-    !isNaN(_monthAfterAdding1Month) &&
-    !isNaN(_monthAfterAddingExtraDaysColumnView) &&
-    _monthAfterAdding1Month !== _monthAfterAddingExtraDaysColumnView
+    !isNaN(_monthAfterAdding1Month) &&
+    !isNaN(_monthAfterAddingExtraDaysColumnView) &&
+    _monthAfterAdding1Month !== _monthAfterAddingExtraDaysColumnView
       ? 2
+      : !isNaN(_monthAfterAdding1Month) && !isNaN(_monthAfterAddingExtraDaysColumnView)
+      ? undefined
       : undefined;

Actually, the current logic is fine - returning undefined for any NaN case is the safe default.


149-153: Do not change — using the store month here is intentional.

The month value is the Booker store's browsing month (YYYY‑MM, see packages/features/bookings/Booker/store.ts) and the prefetch logic intentionally checks whether the browsing month equals the current month and whether today is past two weeks into that month (packages/platform/atoms/booker/BookerWebWrapper.tsx ~lines 149–152). Replacing with the date parameter would change the semantics and can cause incorrect prefetching.

Likely an incorrect or invalid review comment.

Comment on lines +142 to +148
const _month = dayjs(date).month();
const _monthAfterAdding1Month = dayjs(date).add(1, "month").month();
const _monthAfterAddingExtraDays = dayjs(date).add(bookerLayout.extraDays, "day").month();
const _monthAfterAddingExtraDaysColumnView = dayjs(date)
.add(bookerLayout.columnViewExtraDays.current, "day")
.month();

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix NaN propagation in month calculations

The current implementation doesn't handle invalid dates properly. When date is invalid, dayjs(date).month() returns NaN, which then propagates through all the derived calculations. This can cause the prefetch logic to behave unexpectedly.

Add validation to prevent NaN propagation:

-  const _month = dayjs(date).month();
-  const _monthAfterAdding1Month = dayjs(date).add(1, "month").month();
-  const _monthAfterAddingExtraDays = dayjs(date).add(bookerLayout.extraDays, "day").month();
-  const _monthAfterAddingExtraDaysColumnView = dayjs(date)
-    .add(bookerLayout.columnViewExtraDays.current, "day")
-    .month();
+  const parsedDate = dayjs(date);
+  const _month = parsedDate.isValid() ? parsedDate.month() : NaN;
+  const _monthAfterAdding1Month = parsedDate.isValid() ? parsedDate.add(1, "month").month() : NaN;
+  const _monthAfterAddingExtraDays = parsedDate.isValid() ? parsedDate.add(bookerLayout.extraDays, "day").month() : NaN;
+  const _monthAfterAddingExtraDaysColumnView = parsedDate.isValid() 
+    ? parsedDate.add(bookerLayout.columnViewExtraDays.current, "day").month() 
+    : NaN;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const _month = dayjs(date).month();
const _monthAfterAdding1Month = dayjs(date).add(1, "month").month();
const _monthAfterAddingExtraDays = dayjs(date).add(bookerLayout.extraDays, "day").month();
const _monthAfterAddingExtraDaysColumnView = dayjs(date)
.add(bookerLayout.columnViewExtraDays.current, "day")
.month();
const parsedDate = dayjs(date);
const _month = parsedDate.isValid() ? parsedDate.month() : NaN;
const _monthAfterAdding1Month = parsedDate.isValid() ? parsedDate.add(1, "month").month() : NaN;
const _monthAfterAddingExtraDays = parsedDate.isValid() ? parsedDate.add(bookerLayout.extraDays, "day").month() : NaN;
const _monthAfterAddingExtraDaysColumnView = parsedDate.isValid()
? parsedDate.add(bookerLayout.columnViewExtraDays.current, "day").month()
: NaN;

@emrysal emrysal changed the title handle NaN != NaN prefetch fix: handle NaN != NaN prefetch Sep 18, 2025
Copy link
Contributor

@emrysal emrysal left a comment

Choose a reason for hiding this comment

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

LGTM

@emrysal emrysal enabled auto-merge (squash) September 18, 2025 10:07
@emrysal emrysal disabled auto-merge September 18, 2025 10:33
@emrysal emrysal merged commit 98a075d into main Sep 18, 2025
62 of 66 checks passed
@emrysal emrysal deleted the dont-prefetch-next-2-months-when-2-weeks-cross branch September 18, 2025 10:34
emrysal pushed a commit that referenced this pull request Sep 18, 2025
@github-actions
Copy link
Contributor

E2E results are ready!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO platform Anything related to our platform plan ready-for-e2e size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants