@klinking/colander 3.1.0-alpha.7 → 3.1.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/formats/date.cjs +2 -3
  2. package/dist/formats/date.d.cts +10 -14
  3. package/dist/formats/date.d.mts +10 -14
  4. package/dist/formats/date.mjs +2 -3
  5. package/dist/formats/object.cjs +2 -3
  6. package/dist/formats/object.d.cts +10 -14
  7. package/dist/formats/object.d.mts +10 -14
  8. package/dist/formats/object.mjs +2 -3
  9. package/dist/formats/plain-date-time.cjs +2 -3
  10. package/dist/formats/plain-date-time.d.cts +10 -14
  11. package/dist/formats/plain-date-time.d.mts +10 -14
  12. package/dist/formats/plain-date-time.mjs +2 -3
  13. package/dist/formats/plain-date.cjs +2 -3
  14. package/dist/formats/plain-date.d.cts +10 -14
  15. package/dist/formats/plain-date.d.mts +10 -14
  16. package/dist/formats/plain-date.mjs +2 -3
  17. package/dist/formats/plain-month-day.cjs +2 -3
  18. package/dist/formats/plain-month-day.d.cts +10 -14
  19. package/dist/formats/plain-month-day.d.mts +10 -14
  20. package/dist/formats/plain-month-day.mjs +2 -3
  21. package/dist/formats/plain-year-month.cjs +2 -3
  22. package/dist/formats/plain-year-month.d.cts +10 -14
  23. package/dist/formats/plain-year-month.d.mts +10 -14
  24. package/dist/formats/plain-year-month.mjs +2 -3
  25. package/dist/formats/zoned-date-time.cjs +2 -3
  26. package/dist/formats/zoned-date-time.d.cts +10 -14
  27. package/dist/formats/zoned-date-time.d.mts +10 -14
  28. package/dist/formats/zoned-date-time.mjs +2 -3
  29. package/dist/{weeks-view-context-BTojXkys.d.cts → index-B5VJ_WF2.d.mts} +91 -114
  30. package/dist/{weeks-view-context-CFXV8orh.d.mts → index-BMsxaq1s.d.cts} +91 -114
  31. package/dist/index.cjs +1 -1
  32. package/dist/index.d.cts +1 -10
  33. package/dist/index.d.mts +1 -10
  34. package/dist/index.mjs +1 -2
  35. package/dist/{weeks-navigation-CPevz3Xg.cjs → weeks-navigation-CUQApLMk.cjs} +531 -400
  36. package/dist/{weeks-navigation-BSKwFvdP.mjs → weeks-navigation-CWNpF_6M.mjs} +531 -399
  37. package/package.json +21 -18
  38. package/src/calendar-provider.test.tsx +1 -1
  39. package/src/calendar-provider.tsx +8 -2
  40. package/src/compute-weeks-in-window.test.ts +1 -1
  41. package/src/day-cell-state.test.ts +1 -1
  42. package/src/day-cell-state.ts +0 -70
  43. package/src/day-cell-store.test.tsx +273 -0
  44. package/src/day-cell-store.tsx +204 -0
  45. package/src/day-cell.test.tsx +73 -90
  46. package/src/day-cell.tsx +93 -78
  47. package/src/formats/formats.test.ts +1 -1
  48. package/src/grid.event-perf.test.tsx +7 -1
  49. package/src/grid.perf.test.tsx +7 -1
  50. package/src/grid.tsx +17 -15
  51. package/src/keyboard.test.ts +1 -1
  52. package/src/month-separator.test.tsx +1 -1
  53. package/src/month-view.bounds.test.tsx +1 -1
  54. package/src/month-view.test.tsx +89 -1
  55. package/src/month-view.tsx +17 -7
  56. package/src/month-window.test.ts +1 -1
  57. package/src/out-of-range.test.ts +1 -1
  58. package/src/range-preview.test.ts +1 -1
  59. package/src/resolve-first-week.test.ts +1 -1
  60. package/src/store.ts +72 -0
  61. package/src/today.test.tsx +8 -1
  62. package/src/utils.bench.ts +158 -106
  63. package/src/utils.test.ts +1 -1
  64. package/src/view-context.test.tsx +1 -1
  65. package/src/view-context.ts +2 -0
  66. package/src/weeks-grid.tsx +20 -10
  67. package/src/weeks-keyboard.test.ts +1 -1
  68. package/src/weeks-view-state.ts +1 -1
  69. package/src/weeks-view.bounds.test.tsx +1 -1
  70. package/src/weeks-view.test.tsx +1 -1
  71. package/src/weeks-view.tsx +2 -1
  72. package/src/weeks-window.test.ts +1 -1
@@ -1,109 +1,92 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
- import { describe, it, expect } from "vitest";
2
+ import { describe, it, expect } from "vite-plus/test";
3
3
  import {
4
4
  dayCellInstancePropsAreEqual,
5
5
  dayButtonInnerPropsAreEqual,
6
6
  } from "./day-cell";
7
7
 
8
8
  const date = Temporal.PlainDate.from("2026-03-15");
9
-
10
- /** Full derived-state object the comparators read, with field overrides. */
11
- function makeDerived(overrides: Record<string, unknown> = {}) {
12
- return {
13
- root: {},
14
- date,
15
- columnIndex: 0,
16
- orientation: "horizontal",
17
- outsideMonth: false,
18
- hidden: false,
19
- selected: false,
20
- today: false,
21
- disabled: false,
22
- focused: false,
23
- rangeStart: false,
24
- rangeEnd: false,
25
- rangeBoundary: false,
26
- inRange: false,
27
- rangeIndex: false,
28
- rangeLength: false,
29
- rangeHasStart: false,
30
- rangeHasEnd: false,
31
- rangePreviewStart: false,
32
- rangePreviewEnd: false,
33
- rangePreviewBoundary: false,
34
- rangePreviewInRange: false,
35
- rangePreviewIndex: false,
36
- rangePreviewLength: false,
37
- rangePreviewHasStart: false,
38
- rangePreviewHasEnd: false,
39
- isTabTarget: false,
40
- ...overrides,
41
- };
42
- }
9
+ const gridMonth = { year: 2026, month: 3 };
10
+ const render = () => null;
11
+ const onPointerDown = () => {};
43
12
 
44
13
  describe("dayCellInstancePropsAreEqual", () => {
45
- it("returns false when a pass-through prop (className) changes", () => {
46
- const _derivedState = makeDerived();
47
- const prev = { date, _derivedState, className: "a" };
48
- const next = { date, _derivedState, className: "b" };
49
- expect(dayCellInstancePropsAreEqual(prev as never, next as never)).toBe(
50
- false,
51
- );
52
- });
53
-
54
- it("returns false when a pass-through handler identity changes", () => {
55
- const _derivedState = makeDerived();
56
- const prev = { date, _derivedState, onPointerDown: () => {} };
57
- const next = { date, _derivedState, onPointerDown: () => {} };
14
+ // A cell's state comes from the store, so only its props decide whether it
15
+ // can skip a parent re-render.
16
+ it.each([
17
+ {
18
+ description: "unchanged props are equal",
19
+ prev: { date, gridMonth, render, className: "a", onPointerDown },
20
+ next: { date, gridMonth, render, className: "a", onPointerDown },
21
+ expected: true,
22
+ },
23
+ {
24
+ description: "children are ignored (fresh React elements every render)",
25
+ prev: { date, children: <span>a</span> },
26
+ next: { date, children: <span>b</span> },
27
+ expected: true,
28
+ },
29
+ {
30
+ description: "a changed pass-through prop differs",
31
+ prev: { date, className: "a" },
32
+ next: { date, className: "b" },
33
+ expected: false,
34
+ },
35
+ {
36
+ description: "a new pass-through handler identity differs",
37
+ prev: { date, onPointerDown: () => {} },
38
+ next: { date, onPointerDown: () => {} },
39
+ expected: false,
40
+ },
41
+ {
42
+ description: "a new render function identity differs",
43
+ prev: { date, render: () => null },
44
+ next: { date, render: () => null },
45
+ expected: false,
46
+ },
47
+ {
48
+ description: "a new gridMonth identity differs",
49
+ prev: { date, gridMonth: { year: 2026, month: 3 } },
50
+ next: { date, gridMonth: { year: 2026, month: 3 } },
51
+ expected: false,
52
+ },
53
+ {
54
+ description: "a different column differs",
55
+ prev: { date, columnIndex: 0 },
56
+ next: { date, columnIndex: 1 },
57
+ expected: false,
58
+ },
59
+ ])("$description", ({ prev, next, expected }) => {
58
60
  expect(dayCellInstancePropsAreEqual(prev as never, next as never)).toBe(
59
- false,
60
- );
61
- });
62
-
63
- it("returns true when pass-through props are unchanged", () => {
64
- const _derivedState = makeDerived();
65
- const onPointerDown = () => {};
66
- const prev = { date, _derivedState, className: "a", onPointerDown };
67
- const next = { date, _derivedState, className: "a", onPointerDown };
68
- expect(dayCellInstancePropsAreEqual(prev as never, next as never)).toBe(
69
- true,
70
- );
71
- });
72
-
73
- it("still ignores children (fresh React elements every render)", () => {
74
- const _derivedState = makeDerived();
75
- const prev = { date, _derivedState, children: <span>a</span> };
76
- const next = { date, _derivedState, children: <span>b</span> };
77
- expect(dayCellInstancePropsAreEqual(prev as never, next as never)).toBe(
78
- true,
79
- );
80
- });
81
-
82
- it("returns false when a derived-state field changes", () => {
83
- const prev = { date, _derivedState: makeDerived({ selected: false }) };
84
- const next = { date, _derivedState: makeDerived({ selected: true }) };
85
- expect(dayCellInstancePropsAreEqual(prev as never, next as never)).toBe(
86
- false,
61
+ expected,
87
62
  );
88
63
  });
89
64
  });
90
65
 
91
66
  describe("dayButtonInnerPropsAreEqual", () => {
92
- it("returns false when a pass-through prop changes", () => {
93
- const _derivedState = makeDerived();
94
- const prev = { date, _derivedState, "data-x": "1" };
95
- const next = { date, _derivedState, "data-x": "2" };
96
- expect(dayButtonInnerPropsAreEqual(prev as never, next as never)).toBe(
97
- false,
98
- );
99
- });
100
-
101
- it("returns true when pass-through props are unchanged", () => {
102
- const _derivedState = makeDerived();
103
- const prev = { date, _derivedState, "data-x": "1" };
104
- const next = { date, _derivedState, "data-x": "1" };
67
+ const _state = {};
68
+ it.each([
69
+ {
70
+ description: "unchanged props and state are equal",
71
+ prev: { date, _state, "data-x": "1" },
72
+ next: { date, _state, "data-x": "1" },
73
+ expected: true,
74
+ },
75
+ {
76
+ description: "a changed pass-through prop differs",
77
+ prev: { date, _state, "data-x": "1" },
78
+ next: { date, _state, "data-x": "2" },
79
+ expected: false,
80
+ },
81
+ {
82
+ description: "a new cell state object differs",
83
+ prev: { date, _state: {} },
84
+ next: { date, _state: {} },
85
+ expected: false,
86
+ },
87
+ ])("$description", ({ prev, next, expected }) => {
105
88
  expect(dayButtonInnerPropsAreEqual(prev as never, next as never)).toBe(
106
- true,
89
+ expected,
107
90
  );
108
91
  });
109
92
  });
package/src/day-cell.tsx CHANGED
@@ -1,11 +1,19 @@
1
1
  import { mergeProps } from "@base-ui/react/merge-props";
2
2
  import { useRender } from "@base-ui/react/use-render";
3
3
  import type { Temporal as TemporalPoly } from "@js-temporal/polyfill";
4
- import { useContext, useEffect, useRef, memo, forwardRef } from "react";
4
+ import {
5
+ createContext,
6
+ forwardRef,
7
+ memo,
8
+ useContext,
9
+ useEffect,
10
+ useMemo,
11
+ useRef,
12
+ } from "react";
5
13
  import { useCalendarStable } from "./calendar-context";
6
14
  import { WeekDataContext, DayCellDataContext } from "./context";
7
- import { dayCellStateEqual, useDayCellDeriver } from "./day-cell-state";
8
15
  import type { DayCellState } from "./day-cell-state";
16
+ import { useDayCellState, useStandaloneDayCellState } from "./day-cell-store";
9
17
  import { MonthViewStateContext } from "./month-view-context";
10
18
  import type { StateAttributesMapping } from "./types";
11
19
  import type {
@@ -14,7 +22,7 @@ import type {
14
22
  DayCellTemplateState,
15
23
  } from "./types";
16
24
  import { shouldMoveDomFocus } from "./utils";
17
- import { useViewContext, useViewStable } from "./view-context";
25
+ import { useViewStable } from "./view-context";
18
26
 
19
27
  export const dayStateAttributesMapping = {
20
28
  root: () => null,
@@ -51,21 +59,27 @@ export const dayStateAttributesMapping = {
51
59
  rangePreviewHasEnd: (v) => (v ? { "data-range-preview-has-end": "" } : null),
52
60
  } as const satisfies StateAttributesMapping<DayCellTemplateState>;
53
61
 
62
+ /** @internal The enclosing day cell's state, read by its `DayButton`. */
63
+ const DayCellStateContext = createContext<DayCellState | null>(null);
64
+
65
+ type MonthKey = { year: number; month: number };
66
+
54
67
  /** Props for the memoized DayCellInstance. */
55
68
  interface DayCellInstanceProps {
56
69
  render?: DayCellTemplateProps["render"];
57
70
  date: TemporalPoly.PlainDate;
58
71
  columnIndex?: number | undefined;
72
+ gridMonth?: MonthKey | undefined;
59
73
  children?: React.ReactNode;
60
- _derivedState: DayCellState;
61
74
  [key: string]: unknown;
62
75
  }
63
76
 
64
77
  function DayCellInstanceFn(props: DayCellInstanceProps) {
65
- const { render, date, columnIndex, children, _derivedState, ...otherProps } =
78
+ const { render, date, columnIndex, gridMonth, children, ...otherProps } =
66
79
  props;
67
80
 
68
- const state = _derivedState as unknown as DayCellTemplateState;
81
+ const derived = useDayCellState(date, columnIndex, gridMonth);
82
+ const state = derived as unknown as DayCellTemplateState;
69
83
 
70
84
  const defaultProps: Record<string, unknown> = state.hidden
71
85
  ? {
@@ -77,7 +91,7 @@ function DayCellInstanceFn(props: DayCellInstanceProps) {
77
91
  role: "gridcell",
78
92
  "aria-selected": state.selected || undefined,
79
93
  "aria-disabled": state.disabled || undefined,
80
- children: children ?? <DayButton _derivedState={_derivedState} />,
94
+ children: children ?? <DayButton />,
81
95
  };
82
96
 
83
97
  const cell = useRender({
@@ -91,10 +105,16 @@ function DayCellInstanceFn(props: DayCellInstanceProps) {
91
105
 
92
106
  const outsideDisabled =
93
107
  state.hidden || (state.outsideMonth && state.disabled);
108
+ const cellData = useMemo(
109
+ () => ({ date, columnIndex, outsideDisabled }),
110
+ [date, columnIndex, outsideDisabled],
111
+ );
94
112
 
95
113
  return (
96
- <DayCellDataContext.Provider value={{ date, columnIndex, outsideDisabled }}>
97
- {cell}
114
+ <DayCellDataContext.Provider value={cellData}>
115
+ <DayCellStateContext.Provider value={derived}>
116
+ {cell}
117
+ </DayCellStateContext.Provider>
98
118
  </DayCellDataContext.Provider>
99
119
  );
100
120
  }
@@ -123,33 +143,30 @@ const DAY_CELL_HANDLED_KEYS: ReadonlySet<string> = new Set([
123
143
  "render",
124
144
  "date",
125
145
  "columnIndex",
146
+ "gridMonth",
126
147
  "children",
127
- "_derivedState",
128
148
  ]);
129
149
 
130
150
  const DAY_BUTTON_HANDLED_KEYS: ReadonlySet<string> = new Set([
131
151
  "render",
132
152
  "date",
133
153
  "children",
134
- "_derivedState",
154
+ "_state",
135
155
  ]);
136
156
 
157
+ /**
158
+ * Whether a day cell can skip a parent re-render. Its own state comes from
159
+ * the store, so only props are compared here.
160
+ */
137
161
  export function dayCellInstancePropsAreEqual(
138
162
  prev: DayCellInstanceProps,
139
163
  next: DayCellInstanceProps,
140
164
  ): boolean {
141
- // Skip `children` — React elements are always new objects. Child components
142
- // that subscribe to context (e.g. DayButton fallback) get their own
143
- // re-render via context; the optimised internal DayButton reads only
144
- // stable context and is separately memo'd.
145
- if (
146
- prev.date !== next.date ||
147
- prev.render !== next.render ||
148
- prev.columnIndex !== next.columnIndex
149
- )
150
- return false;
151
165
  return (
152
- dayCellStateEqual(prev._derivedState, next._derivedState) &&
166
+ prev.date === next.date &&
167
+ prev.render === next.render &&
168
+ prev.columnIndex === next.columnIndex &&
169
+ prev.gridMonth === next.gridMonth &&
153
170
  passThroughPropsEqual(prev, next, DAY_CELL_HANDLED_KEYS)
154
171
  );
155
172
  }
@@ -159,6 +176,19 @@ const DayCellInstance = memo(
159
176
  dayCellInstancePropsAreEqual,
160
177
  ) as typeof DayCellInstanceFn;
161
178
 
179
+ /** The cells of a whole month, for a `DayCellTemplate` outside any week row. */
180
+ function MonthDayCells(props: Omit<DayCellTemplateProps, "date">) {
181
+ const monthState = useContext(MonthViewStateContext);
182
+ const days = monthState?.weeks.flat() ?? [];
183
+ return (
184
+ <>
185
+ {days.map((day) => (
186
+ <DayCellInstance key={day.toString()} {...props} date={day} />
187
+ ))}
188
+ </>
189
+ );
190
+ }
191
+
162
192
  /**
163
193
  * Renders one `<td role="gridcell">` per day. Exposes data-attributes for
164
194
  * `selected`, `today`, `disabled`, `outside-month`, `focused`,
@@ -170,31 +200,28 @@ const DayCellInstance = memo(
170
200
  export function DayCellTemplate(props: DayCellTemplateProps) {
171
201
  const { date: dateProp, ...restProps } = props;
172
202
  const weekData = useContext(WeekDataContext);
173
- const monthState = useContext(MonthViewStateContext);
174
- const derive = useDayCellDeriver();
175
203
 
176
204
  if (dateProp) {
177
205
  return (
178
206
  <DayCellInstance
179
207
  {...restProps}
180
208
  date={dateProp}
181
- _derivedState={derive(dateProp)}
209
+ gridMonth={weekData?.gridMonth}
182
210
  />
183
211
  );
184
212
  }
185
213
 
186
- const days = weekData ? weekData.days : (monthState?.weeks.flat() ?? []);
187
- const perWeek = weekData != null;
214
+ if (!weekData) return <MonthDayCells {...restProps} />;
188
215
 
189
216
  return (
190
217
  <>
191
- {days.map((day, i) => (
218
+ {weekData.days.map((day, i) => (
192
219
  <DayCellInstance
193
220
  key={day.toString()}
194
221
  {...restProps}
195
222
  date={day}
196
- columnIndex={perWeek ? i : undefined}
197
- _derivedState={derive(day, perWeek ? i : undefined)}
223
+ columnIndex={i}
224
+ gridMonth={weekData.gridMonth}
198
225
  />
199
226
  ))}
200
227
  </>
@@ -205,7 +232,7 @@ export function DayCellTemplate(props: DayCellTemplateProps) {
205
232
  interface DayButtonInnerProps {
206
233
  render?: DayButtonProps["render"];
207
234
  date: TemporalPoly.PlainDate;
208
- _derivedState?: DayCellState;
235
+ _state: DayCellState;
209
236
  [key: string]: unknown;
210
237
  }
211
238
 
@@ -213,17 +240,16 @@ function DayButtonInnerFn(
213
240
  props: DayButtonInnerProps,
214
241
  ref: React.ForwardedRef<HTMLButtonElement>,
215
242
  ) {
216
- const { render, date, _derivedState, ...otherProps } = props;
243
+ const { render, date, _state, ...otherProps } = props;
217
244
  const { onSelect, locale, readOnly, setHoveredDate } = useCalendarStable();
218
- const { setFocusedDate } = useViewContext();
219
- const { gridFocusedRef } = useViewStable();
245
+ const { gridFocusedRef, setFocusedDate } = useViewStable();
220
246
 
221
247
  const internalRef = useRef<HTMLButtonElement>(null);
222
248
 
223
- const isHidden = _derivedState?.hidden ?? false;
224
- const isFocused = _derivedState?.focused ?? false;
225
- const isTabTarget = _derivedState?.isTabTarget ?? false;
226
- const isDisabled = _derivedState?.disabled ?? false;
249
+ const isHidden = _state.hidden;
250
+ const isFocused = _state.focused;
251
+ const isTabTarget = _state.isTabTarget;
252
+ const isDisabled = _state.disabled;
227
253
 
228
254
  useEffect(() => {
229
255
  if (
@@ -234,7 +260,7 @@ function DayButtonInnerFn(
234
260
  }
235
261
  }, [isFocused, gridFocusedRef]);
236
262
 
237
- const state = _derivedState as unknown as DayCellTemplateState;
263
+ const state = _state as unknown as DayCellTemplateState;
238
264
 
239
265
  const defaultProps: Record<string, unknown> = isHidden
240
266
  ? {}
@@ -278,12 +304,12 @@ export function dayButtonInnerPropsAreEqual(
278
304
  prev: DayButtonInnerProps,
279
305
  next: DayButtonInnerProps,
280
306
  ): boolean {
281
- if (prev.date !== next.date || prev.render !== next.render) return false;
282
- if (!passThroughPropsEqual(prev, next, DAY_BUTTON_HANDLED_KEYS)) return false;
283
- const a = prev._derivedState;
284
- const b = next._derivedState;
285
- if (!a || !b) return a === b;
286
- return dayCellStateEqual(a, b);
307
+ return (
308
+ prev.date === next.date &&
309
+ prev.render === next.render &&
310
+ prev._state === next._state &&
311
+ passThroughPropsEqual(prev, next, DAY_BUTTON_HANDLED_KEYS)
312
+ );
287
313
  }
288
314
 
289
315
  // The `as any` casts are needed because DayButtonInnerProps uses an index
@@ -303,30 +329,28 @@ const DayButtonInner = memo(
303
329
  * Must be used inside a {@link DayCellTemplate} or given an explicit `date` prop.
304
330
  */
305
331
  function DayButtonFn(
306
- props: DayButtonProps & {
307
- _derivedState?: DayCellState;
308
- },
332
+ props: DayButtonProps,
309
333
  ref: React.ForwardedRef<HTMLButtonElement>,
310
334
  ) {
311
- const { date: dateProp, _derivedState, ...restProps } = props;
335
+ const { date: dateProp, ...restProps } = props;
336
+ const cellState = useContext(DayCellStateContext);
312
337
  const cellData = useContext(DayCellDataContext);
313
338
 
314
- const resolvedDate = dateProp ?? cellData?.date;
339
+ // Inside a cell for the same date, reuse the cell's state.
340
+ if (cellState && (!dateProp || dateProp.equals(cellState.date))) {
341
+ return (
342
+ <DayButtonInner
343
+ {...restProps}
344
+ ref={ref}
345
+ date={cellState.date}
346
+ _state={cellState}
347
+ />
348
+ );
349
+ }
315
350
 
351
+ const resolvedDate = dateProp ?? cellData?.date;
316
352
  if (resolvedDate) {
317
- // If we have derived state passed from parent, use it directly
318
- if (_derivedState) {
319
- return (
320
- <DayButtonInner
321
- {...restProps}
322
- ref={ref}
323
- date={resolvedDate}
324
- _derivedState={_derivedState}
325
- />
326
- );
327
- }
328
- // Fallback: compute state (for standalone DayButton usage with explicit date)
329
- return <DayButtonFallback ref={ref} {...restProps} date={resolvedDate} />;
353
+ return <StandaloneDayButton {...restProps} ref={ref} date={resolvedDate} />;
330
354
  }
331
355
 
332
356
  throw new Error(
@@ -335,30 +359,21 @@ function DayButtonFn(
335
359
  }
336
360
 
337
361
  export const DayButton = forwardRef(DayButtonFn) as (
338
- props: DayButtonProps & {
339
- _derivedState?: DayCellState;
340
- } & React.RefAttributes<HTMLButtonElement>,
362
+ props: DayButtonProps & React.RefAttributes<HTMLButtonElement>,
341
363
  ) => React.ReactElement | null;
342
364
 
343
- /** Fallback for standalone DayButton usage that needs to read context. */
344
- function DayButtonFallbackFn(
365
+ /** A `DayButton` outside any day cell: subscribes to its own date's state. */
366
+ function StandaloneDayButtonFn(
345
367
  props: Omit<DayButtonProps, "date"> & { date: TemporalPoly.PlainDate },
346
368
  ref: React.ForwardedRef<HTMLButtonElement>,
347
369
  ) {
348
370
  const { date, ...restProps } = props;
349
- const derive = useDayCellDeriver();
371
+ const state = useStandaloneDayCellState(date);
350
372
 
351
- return (
352
- <DayButtonInner
353
- {...restProps}
354
- ref={ref}
355
- date={date}
356
- _derivedState={derive(date)}
357
- />
358
- );
373
+ return <DayButtonInner {...restProps} ref={ref} date={date} _state={state} />;
359
374
  }
360
375
 
361
- const DayButtonFallback = forwardRef(DayButtonFallbackFn) as (
376
+ const StandaloneDayButton = forwardRef(StandaloneDayButtonFn) as (
362
377
  props: Omit<DayButtonProps, "date"> & {
363
378
  date: TemporalPoly.PlainDate;
364
379
  } & React.RefAttributes<HTMLButtonElement>,
@@ -1,6 +1,6 @@
1
1
  /// <reference types="vite/client" />
2
2
  import * as root from "@klinking/colander";
3
- import { describe, it, expect } from "vitest";
3
+ import { describe, it, expect } from "vite-plus/test";
4
4
 
5
5
  const formatModules = import.meta.glob<Record<string, unknown>>(
6
6
  ["./*.ts", "!./*.test.ts"],
@@ -2,7 +2,13 @@ import { Temporal } from "@js-temporal/polyfill";
2
2
  import { render, act, fireEvent } from "@testing-library/react";
3
3
  import { Profiler, type ProfilerOnRenderCallback } from "react";
4
4
  // @vitest-environment jsdom
5
- import { describe, it, expect, beforeAll, type TestOptions } from "vitest";
5
+ import {
6
+ describe,
7
+ it,
8
+ expect,
9
+ beforeAll,
10
+ type TestOptions,
11
+ } from "vite-plus/test";
6
12
 
7
13
  const perfOptions: TestOptions = { retry: 3 };
8
14
  import { Grid } from "./grid";
@@ -2,7 +2,13 @@ import { Temporal } from "@js-temporal/polyfill";
2
2
  import { render } from "@testing-library/react";
3
3
  import { Profiler, type ProfilerOnRenderCallback } from "react";
4
4
  // @vitest-environment jsdom
5
- import { describe, it, expect, beforeAll, type TestOptions } from "vitest";
5
+ import {
6
+ describe,
7
+ it,
8
+ expect,
9
+ beforeAll,
10
+ type TestOptions,
11
+ } from "vite-plus/test";
6
12
 
7
13
  const perfOptions: TestOptions = { retry: 3 };
8
14
  import { WeekDataContext } from "./context";
package/src/grid.tsx CHANGED
@@ -571,26 +571,28 @@ export function WeekTemplate(props: WeekTemplateProps) {
571
571
  : undefined,
572
572
  [gridMonthCtx],
573
573
  );
574
- const Instance = WeekInstance;
574
+ const gridRowIndex = outerWeekData?.gridRowIndex;
575
+ // Built once per set of weeks, so a focus or selection change that
576
+ // re-renders this template leaves the day cells' context untouched.
577
+ const weekValues = useMemo(
578
+ () =>
579
+ weeks.map((weekDays, i) => ({
580
+ days: weekDays,
581
+ weekIndex: i,
582
+ ...(gridMonth !== undefined && { gridMonth }),
583
+ ...(gridRowIndex !== undefined && { gridRowIndex }),
584
+ })),
585
+ [weeks, gridMonth, gridRowIndex],
586
+ );
575
587
 
576
588
  return (
577
589
  <>
578
- {weeks.map((weekDays, i) => {
579
- const firstDay = weekDays[0];
590
+ {weekValues.map((value) => {
591
+ const firstDay = value.days[0];
580
592
  if (firstDay === undefined) return null;
581
593
  return (
582
- <WeekDataContext.Provider
583
- key={firstDay.toString()}
584
- value={{
585
- days: weekDays,
586
- weekIndex: i,
587
- ...(gridMonth !== undefined && { gridMonth }),
588
- ...(outerWeekData?.gridRowIndex !== undefined && {
589
- gridRowIndex: outerWeekData.gridRowIndex,
590
- }),
591
- }}
592
- >
593
- <Instance {...props} />
594
+ <WeekDataContext.Provider key={firstDay.toString()} value={value}>
595
+ <WeekInstance {...props} />
594
596
  </WeekDataContext.Provider>
595
597
  );
596
598
  })}
@@ -1,4 +1,4 @@
1
- import { describe, it, expect } from "vitest";
1
+ import { describe, it, expect } from "vite-plus/test";
2
2
  import { computeNextFocusDate, computeMonthJumpTarget } from "./keyboard";
3
3
  import type { KeyboardNavInput } from "./keyboard";
4
4
  import { temporalVariants } from "./test-temporal";
@@ -1,5 +1,5 @@
1
1
  import { render, cleanup, within } from "@testing-library/react";
2
- import { describe, it, expect, afterEach } from "vitest";
2
+ import { describe, it, expect, afterEach } from "vite-plus/test";
3
3
  import {
4
4
  MonthSeparator,
5
5
  MonthSeparatorMonth,
@@ -1,6 +1,6 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { act, cleanup, render, screen } from "@testing-library/react";
3
- import { afterEach, describe, expect, it, vi } from "vitest";
3
+ import { afterEach, describe, expect, it, vi } from "vite-plus/test";
4
4
  import { MonthView } from "./month-view";
5
5
  import type { MonthViewProps } from "./month-view";
6
6
  import { useMonthViewStable, useMonthViewState } from "./month-view-context";