@@ -53,6 +53,7 @@ interface CalendarRootStateOpts
5353 WritableBoxedValues < {
5454 value : DateValue | undefined | DateValue [ ] ;
5555 placeholder : DateValue ;
56+ months : Month < DateValue > [ ] ;
5657 } > ,
5758 ReadableBoxedValues < {
5859 preventDeselect : boolean ;
@@ -94,7 +95,7 @@ export class CalendarRootState {
9495 }
9596
9697 readonly opts : CalendarRootStateOpts ;
97- readonly visibleMonths = $derived . by ( ( ) => this . months . map ( ( month ) => month . value ) ) ;
98+ readonly visibleMonths = $derived . by ( ( ) => this . # months. map ( ( month ) => month . value ) ) ;
9899 readonly formatter : Formatter ;
99100 readonly accessibleHeadingId = useId ( ) ;
100101 readonly domContext : DOMContext ;
@@ -134,7 +135,7 @@ export class CalendarRootState {
134135 this . announcer = getAnnouncer ( this . domContext . getDocument ( ) ) ;
135136 } ) ;
136137
137- this . months = createMonths ( {
138+ this . opts . months . current = createMonths ( {
138139 dateObj : this . opts . placeholder . current ,
139140 weekStartsOn : this . opts . weekStartsOn . current ,
140141 locale : this . opts . locale . current ,
@@ -156,7 +157,7 @@ export class CalendarRootState {
156157 locale : this . opts . locale ,
157158 fixedWeeks : this . opts . fixedWeeks ,
158159 numberOfMonths : this . opts . numberOfMonths ,
159- setMonths : ( months : Month < DateValue > [ ] ) => ( this . months = months ) ,
160+ setMonths : ( months : Month < DateValue > [ ] ) => ( this . opts . months . current = months ) ,
160161 } ) ;
161162
162163 /**
@@ -217,8 +218,24 @@ export class CalendarRootState {
217218 } ) ;
218219 }
219220
221+ /**
222+ * Currently displayed months, with default value fallback for SSR,
223+ * as boxes don't update server-side.
224+ */
225+ get #months( ) {
226+ return this . opts . months . current . length
227+ ? this . opts . months . current
228+ : createMonths ( {
229+ dateObj : this . opts . placeholder . current ,
230+ weekStartsOn : this . opts . weekStartsOn . current ,
231+ locale : this . opts . locale . current ,
232+ fixedWeeks : this . opts . fixedWeeks . current ,
233+ numberOfMonths : this . opts . numberOfMonths . current ,
234+ } ) ;
235+ }
236+
220237 setMonths ( months : Month < DateValue > [ ] ) {
221- this . months = months ;
238+ this . opts . months . current = months ;
222239 }
223240
224241 /**
@@ -230,7 +247,7 @@ export class CalendarRootState {
230247 */
231248 readonly weekdays = $derived . by ( ( ) => {
232249 return getWeekdays ( {
233- months : this . months ,
250+ months : this . # months,
234251 formatter : this . formatter ,
235252 weekdayFormat : this . opts . weekdayFormat . current ,
236253 } ) ;
@@ -293,7 +310,7 @@ export class CalendarRootState {
293310 setMonths : this . setMonths ,
294311 setPlaceholder : ( date : DateValue ) => ( this . opts . placeholder . current = date ) ,
295312 weekStartsOn : this . opts . weekStartsOn . current ,
296- months : this . months ,
313+ months : this . # months,
297314 } ) ;
298315 }
299316
@@ -309,7 +326,7 @@ export class CalendarRootState {
309326 setMonths : this . setMonths ,
310327 setPlaceholder : ( date : DateValue ) => ( this . opts . placeholder . current = date ) ,
311328 weekStartsOn : this . opts . weekStartsOn . current ,
312- months : this . months ,
329+ months : this . # months,
313330 } ) ;
314331 }
315332
@@ -332,15 +349,15 @@ export class CalendarRootState {
332349 isNextButtonDisabled = $derived . by ( ( ) => {
333350 return getIsNextButtonDisabled ( {
334351 maxValue : this . opts . maxValue . current ,
335- months : this . months ,
352+ months : this . # months,
336353 disabled : this . opts . disabled . current ,
337354 } ) ;
338355 } ) ;
339356
340357 isPrevButtonDisabled = $derived . by ( ( ) => {
341358 return getIsPrevButtonDisabled ( {
342359 minValue : this . opts . minValue . current ,
343- months : this . months ,
360+ months : this . # months,
344361 disabled : this . opts . disabled . current ,
345362 } ) ;
346363 } ) ;
@@ -367,7 +384,7 @@ export class CalendarRootState {
367384 this . opts . monthFormat . current ;
368385 this . opts . yearFormat . current ;
369386 return getCalendarHeadingValue ( {
370- months : this . months ,
387+ months : this . # months,
371388 formatter : this . formatter ,
372389 locale : this . opts . locale . current ,
373390 } ) ;
@@ -408,7 +425,7 @@ export class CalendarRootState {
408425 calendarNode : this . opts . ref . current ,
409426 isPrevButtonDisabled : this . isPrevButtonDisabled ,
410427 isNextButtonDisabled : this . isNextButtonDisabled ,
411- months : this . months ,
428+ months : this . # months,
412429 numberOfMonths : this . opts . numberOfMonths . current ,
413430 } ) ;
414431 }
@@ -509,7 +526,7 @@ export class CalendarRootState {
509526 }
510527
511528 readonly snippetProps = $derived . by ( ( ) => ( {
512- months : this . months ,
529+ months : this . # months,
513530 weekdays : this . weekdays ,
514531 } ) ) ;
515532
0 commit comments