@@ -50,6 +50,7 @@ type CalendarRootStateProps = WithRefProps<
5050 WritableBoxedValues < {
5151 value : DateValue | undefined | DateValue [ ] ;
5252 placeholder : DateValue ;
53+ months : Month < DateValue > [ ] ;
5354 } > &
5455 ReadableBoxedValues < {
5556 preventDeselect : boolean ;
@@ -80,8 +81,7 @@ type CalendarRootStateProps = WithRefProps<
8081> ;
8182
8283export class CalendarRootState {
83- months : Month < DateValue > [ ] = $state ( [ ] ) ;
84- visibleMonths = $derived . by ( ( ) => this . months . map ( ( month ) => month . value ) ) ;
84+ visibleMonths = $derived . by ( ( ) => this . #months. map ( ( month ) => month . value ) ) ;
8585 announcer : Announcer ;
8686 formatter : Formatter ;
8787 accessibleHeadingId = useId ( ) ;
@@ -109,7 +109,7 @@ export class CalendarRootState {
109109
110110 useRefById ( opts ) ;
111111
112- this . months = createMonths ( {
112+ this . opts . months . current = createMonths ( {
113113 dateObj : this . opts . placeholder . current ,
114114 weekStartsOn : this . opts . weekStartsOn . current ,
115115 locale : this . opts . locale . current ,
@@ -154,7 +154,7 @@ export class CalendarRootState {
154154 locale : this . opts . locale ,
155155 fixedWeeks : this . opts . fixedWeeks ,
156156 numberOfMonths : this . opts . numberOfMonths ,
157- setMonths : ( months : Month < DateValue > [ ] ) => ( this . months = months ) ,
157+ setMonths : ( months : Month < DateValue > [ ] ) => ( this . opts . months . current = months ) ,
158158 } ) ;
159159
160160 /**
@@ -212,8 +212,24 @@ export class CalendarRootState {
212212 } ) ;
213213 }
214214
215+ /**
216+ * Currently displayed months, with default value fallback for SSR,
217+ * as boxes don't update server-side.
218+ */
219+ get #months( ) {
220+ return this . opts . months . current . length
221+ ? this . opts . months . current
222+ : createMonths ( {
223+ dateObj : this . opts . placeholder . current ,
224+ weekStartsOn : this . opts . weekStartsOn . current ,
225+ locale : this . opts . locale . current ,
226+ fixedWeeks : this . opts . fixedWeeks . current ,
227+ numberOfMonths : this . opts . numberOfMonths . current ,
228+ } ) ;
229+ }
230+
215231 setMonths ( months : Month < DateValue > [ ] ) {
216- this . months = months ;
232+ this . opts . months . current = months ;
217233 }
218234
219235 /**
@@ -225,7 +241,7 @@ export class CalendarRootState {
225241 */
226242 weekdays = $derived . by ( ( ) => {
227243 return getWeekdays ( {
228- months : this . months ,
244+ months : this . # months,
229245 formatter : this . formatter ,
230246 weekdayFormat : this . opts . weekdayFormat . current ,
231247 } ) ;
@@ -243,7 +259,7 @@ export class CalendarRootState {
243259 setMonths : this . setMonths ,
244260 setPlaceholder : ( date : DateValue ) => ( this . opts . placeholder . current = date ) ,
245261 weekStartsOn : this . opts . weekStartsOn . current ,
246- months : this . months ,
262+ months : this . # months,
247263 } ) ;
248264 }
249265
@@ -259,7 +275,7 @@ export class CalendarRootState {
259275 setMonths : this . setMonths ,
260276 setPlaceholder : ( date : DateValue ) => ( this . opts . placeholder . current = date ) ,
261277 weekStartsOn : this . opts . weekStartsOn . current ,
262- months : this . months ,
278+ months : this . # months,
263279 } ) ;
264280 }
265281
@@ -282,15 +298,15 @@ export class CalendarRootState {
282298 isNextButtonDisabled = $derived . by ( ( ) => {
283299 return getIsNextButtonDisabled ( {
284300 maxValue : this . opts . maxValue . current ,
285- months : this . months ,
301+ months : this . # months,
286302 disabled : this . opts . disabled . current ,
287303 } ) ;
288304 } ) ;
289305
290306 isPrevButtonDisabled = $derived . by ( ( ) => {
291307 return getIsPrevButtonDisabled ( {
292308 minValue : this . opts . minValue . current ,
293- months : this . months ,
309+ months : this . # months,
294310 disabled : this . opts . disabled . current ,
295311 } ) ;
296312 } ) ;
@@ -315,7 +331,7 @@ export class CalendarRootState {
315331
316332 headingValue = $derived . by ( ( ) => {
317333 return getCalendarHeadingValue ( {
318- months : this . months ,
334+ months : this . # months,
319335 formatter : this . formatter ,
320336 locale : this . opts . locale . current ,
321337 } ) ;
@@ -356,7 +372,7 @@ export class CalendarRootState {
356372 calendarNode : this . opts . ref . current ,
357373 isPrevButtonDisabled : this . isPrevButtonDisabled ,
358374 isNextButtonDisabled : this . isNextButtonDisabled ,
359- months : this . months ,
375+ months : this . # months,
360376 numberOfMonths : this . opts . numberOfMonths . current ,
361377 } ) ;
362378 }
@@ -437,10 +453,12 @@ export class CalendarRootState {
437453 } ) ;
438454 }
439455
440- snippetProps = $derived . by ( ( ) => ( {
441- months : this . months ,
442- weekdays : this . weekdays ,
443- } ) ) ;
456+ snippetProps = $derived . by ( ( ) => {
457+ return {
458+ months : this . #months,
459+ weekdays : this . weekdays ,
460+ } ;
461+ } ) ;
444462
445463 getBitsAttr ( part : CalendarParts ) {
446464 return `data-bits-calendar-${ part } ` ;
0 commit comments