Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(settings): stop a cleared time zone from crashing project settings (#103515)

posthog[bot]bc6efeaddd49
diff --git a/frontend/src/scenes/settings/environment/TimezoneConfig.test.tsx b/frontend/src/scenes/settings/environment/TimezoneConfig.test.tsx
new file mode 100644
index 000000000000..30ee82430264
--- /dev/null
+++ b/frontend/src/scenes/settings/environment/TimezoneConfig.test.tsx
@@ -0,0 +1,44 @@
+import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'
+
+import '@testing-library/jest-dom'
+
+import { cleanup, render, screen } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+import { expectLogic } from 'kea-test-utils'
+
+import { OrganizationMembershipLevel } from 'lib/constants'
+import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
+import { teamLogic } from 'scenes/teamLogic'
+
+import { initKeaTests } from '~/test/init'
+
+import { TimezoneConfig } from './TimezoneConfig'
+
+describe('<TimezoneConfig />', () => {
+ beforeEach(async () => {
+ initKeaTests()
+ teamLogic.mount()
+ preflightLogic.mount()
+ teamLogic.actions.loadCurrentTeamSuccess({
+ ...MOCK_DEFAULT_TEAM,
+ timezone: 'Europe/Madrid',
+ effective_membership_level: OrganizationMembershipLevel.Admin,
+ })
+ await expectLogic(preflightLogic).toFinishAllListeners()
+ })
+
+ afterEach(() => {
+ cleanup()
+ })
+
+ it('keeps the current time zone when the selection is cleared with backspace', async () => {
+ const { container } = render(<TimezoneConfig />)
+ const input = container.querySelector('input[type="text"]') as HTMLInputElement
+
+ await userEvent.click(input)
+ await userEvent.keyboard('{Backspace}')
+
+ expect(screen.getByText('Europe / Madrid (UTC+1:00)')).toBeInTheDocument()
+ await expectLogic(teamLogic).toNotHaveDispatchedActions(['updateCurrentTeam'])
+ })
+})
diff --git a/frontend/src/scenes/settings/environment/TimezoneConfig.tsx b/frontend/src/scenes/settings/environment/TimezoneConfig.tsx
index 5bd3212e44e8..e15b24dc4c07 100644
--- a/frontend/src/scenes/settings/environment/TimezoneConfig.tsx
+++ b/frontend/src/scenes/settings/environment/TimezoneConfig.tsx
@@ -37,6 +37,10 @@ export function TimezoneConfig({ displayWarning = true }: { displayWarning?: boo
virtualized
onChange={([newTimezone]): void => {
// This is a string for a single-mode select, but typing is poor
+ // Backspace on an empty input clears the selection, but a time zone is always required
+ if (!newTimezone) {
+ return
+ }
if (!preflight?.available_timezones) {
throw new Error('No timezones are available')
}