fix(17): IN-07 memoize Intl.DateTimeFormat timezone resolution
This commit is contained in:
@@ -153,7 +153,12 @@ export function CalendarShell() {
|
|||||||
// IANATimezone (the config's timezone type) is declared but not exported by @schedule-x/calendar,
|
// IANATimezone (the config's timezone type) is declared but not exported by @schedule-x/calendar,
|
||||||
// so derive it from useCalendarApp's config parameter rather than importing it.
|
// so derive it from useCalendarApp's config parameter rather than importing it.
|
||||||
type SxTimeZone = NonNullable<Parameters<typeof useCalendarApp>[0]['timezone']>;
|
type SxTimeZone = NonNullable<Parameters<typeof useCalendarApp>[0]['timezone']>;
|
||||||
const displayTimeZone: SxTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
// IN-07: memoize so this stable value never changes identity across renders —
|
||||||
|
// it feeds the useCalendarApp config the file works hard to keep stable.
|
||||||
|
const displayTimeZone = useMemo<SxTimeZone>(
|
||||||
|
() => Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
// useCalendarApp — config is stable; plugins passed as second argument
|
// useCalendarApp — config is stable; plugins passed as second argument
|
||||||
const calendar = useCalendarApp(
|
const calendar = useCalendarApp(
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
* Security: client isAdmin gate is UX only. Server 403 is the real boundary (D-03).
|
* Security: client isAdmin gate is UX only. Server 403 is the real boundary (D-03).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useState, useRef, useEffect } from 'react';
|
import { useState, useRef, useEffect, useMemo } from 'react';
|
||||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
import { CheckCircle, AlertCircle, Loader2 } from 'lucide-react';
|
import { CheckCircle, AlertCircle, Loader2 } from 'lucide-react';
|
||||||
import {
|
import {
|
||||||
@@ -157,8 +157,9 @@ export function AdminPage() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Detected browser timezone (D-02)
|
// Detected browser timezone (D-02). IN-07: memoize — the resolved zone is
|
||||||
const detectedTz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
// stable for the session, no need to recompute every render.
|
||||||
|
const detectedTz = useMemo(() => Intl.DateTimeFormat().resolvedOptions().timeZone, []);
|
||||||
|
|
||||||
// Effective timezone input value: local override → stored value → ''
|
// Effective timezone input value: local override → stored value → ''
|
||||||
const storedTimezone = timezoneQuery.data?.timezone ?? '';
|
const storedTimezone = timezoneQuery.data?.timezone ?? '';
|
||||||
|
|||||||
Reference in New Issue
Block a user