Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions packages/platform/atoms/booker/BookerWebWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,33 @@ const BookerPlatformWrapperComponent = (props: BookerWebWrapperAtomProps) => {

const isEmbed = useIsEmbed();

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();

Comment on lines +142 to +148
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;

const _isValidDate = dayjs(date).isValid();
const _2WeeksAfter = dayjs(month).startOf("month").add(2, "week");
const _isSameMonth = dayjs().isSame(dayjs(month), "month");
const _isAfter2Weeks = dayjs().isAfter(_2WeeksAfter);

const prefetchNextMonth =
(bookerLayout.layout === BookerLayouts.WEEK_VIEW &&
!!bookerLayout.extraDays &&
dayjs(date).month() !== dayjs(date).add(bookerLayout.extraDays, "day").month()) ||
(bookerLayout.layout === BookerLayouts.COLUMN_VIEW &&
dayjs(date).month() !== dayjs(date).add(bookerLayout.columnViewExtraDays.current, "day").month()) ||
_month !== _monthAfterAddingExtraDays) ||
(bookerLayout.layout === BookerLayouts.COLUMN_VIEW && _month !== _monthAfterAddingExtraDaysColumnView) ||
((bookerLayout.layout === BookerLayouts.MONTH_VIEW || bookerLayout.layout === "mobile") &&
(!dayjs(date).isValid() || dayjs().isSame(dayjs(month), "month")) &&
dayjs().isAfter(dayjs(month).startOf("month").add(2, "week")));
(!_isValidDate || _isSameMonth) &&
_isAfter2Weeks);

const monthCount =
((bookerLayout.layout !== BookerLayouts.WEEK_VIEW && bookerState === "selecting_time") ||
bookerLayout.layout === BookerLayouts.COLUMN_VIEW) &&
dayjs(date).add(1, "month").month() !==
dayjs(date).add(bookerLayout.columnViewExtraDays.current, "day").month()
!isNaN(_monthAfterAdding1Month) &&
!isNaN(_monthAfterAddingExtraDaysColumnView) &&
Comment on lines +166 to +167
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

_monthAfterAdding1Month !== _monthAfterAddingExtraDaysColumnView
? 2
: undefined;
/**
Expand Down
Loading