Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(settings): show a time zone only once core has stored it

M3gA-Mind821838eac73f
diff --git a/app/src/components/TimezoneSelect.test.tsx b/app/src/components/TimezoneSelect.test.tsx
index 8f35be2d12..f4eecfae05 100644
--- a/app/src/components/TimezoneSelect.test.tsx
+++ b/app/src/components/TimezoneSelect.test.tsx
@@ -80,6 +80,20 @@ describe('TimezoneSelect', () => {
expect(screen.queryByRole('option', { name: 'EST' })).toBeNull();
});
+ it('shows the old zone until the save succeeds', async () => {
+ getMock.mockResolvedValue(settings('Europe/Berlin'));
+ let finish: (value: unknown) => void = () => {};
+ updateMock.mockReturnValue(new Promise(resolve => (finish = resolve)));
+ render();
+ const select = (await screen.findByTestId('timezone-select')) as HTMLSelectElement;
+ await waitFor(() => expect(select.value).toBe('Europe/Berlin'));
+ fireEvent.change(select, { target: { value: 'Asia/Tokyo' } });
+ await waitFor(() => expect(select.disabled).toBe(true));
+ expect(select.value).toBe('Europe/Berlin');
+ finish({ result: {}, logs: [] });
+ await waitFor(() => expect(select.value).toBe('Asia/Tokyo'));
+ });
+
it('is disabled while a save is in flight, so picks cannot overlap', async () => {
getMock.mockResolvedValue(settings('Europe/Berlin'));
let finish: (value: unknown) => void = () => {};
diff --git a/app/src/components/TimezoneSelect.tsx b/app/src/components/TimezoneSelect.tsx
index 5e119d60b8..53584b8ce2 100644
--- a/app/src/components/TimezoneSelect.tsx
+++ b/app/src/components/TimezoneSelect.tsx
@@ -64,25 +64,18 @@ const TimezoneSelect = ({ ariaLabel }: TimezoneSelectProps) => {
const change = async (value: string) => {
const timezone = value === FOLLOW_DEVICE ? null : value;
- const previous = settings;
- setSettings(current => (current ? { ...current, timezone } : current));
setFailed(false);
// The picker is disabled until this save settles, so two picks cannot
- // race and land out of order.
+ // race and land out of order. Nothing is shown as chosen until core has
+ // stored it, and then exactly what it stored (no re-read).
setSaving(true);
try {
- try {
- await openhumanUpdateUserTimezone(timezone);
- } catch {
- setSettings(previous);
- setFailed(true);
- return;
- }
- // Saved: show exactly what was stored. No re-read, so a late or
- // stale read can never put the previous zone back on screen.
+ await openhumanUpdateUserTimezone(timezone);
setSettings(current =>
current ? { ...current, timezone, effective: timezone ?? current.device ?? 'UTC' } : current
);
+ } catch {
+ setFailed(true);
} finally {
setSaving(false);
}