Skip to content

Commit df021b3

Browse files
committed
fix(editor): keep a retry number field's value when it is blurred untouched
Committing on blur normalized the draft unconditionally, and an untouched field's draft is null — which normalizes to the default. Focusing and leaving Max tries silently reset a configured 5 back to 3.
1 parent 9191ad8 commit df021b3

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
import { act } from 'react'
5+
import { createRoot, type Root } from 'react-dom/client'
6+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
7+
import { RetrySettings } from './retry-settings'
8+
9+
const policy = { enabled: true as const, maxTries: 5, waitBetweenTriesMs: 2000 }
10+
11+
let container: HTMLDivElement
12+
let root: Root
13+
14+
beforeEach(() => {
15+
container = document.createElement('div')
16+
document.body.appendChild(container)
17+
root = createRoot(container)
18+
})
19+
20+
afterEach(() => {
21+
act(() => root.unmount())
22+
container.remove()
23+
})
24+
25+
function renderSettings(props: Partial<Parameters<typeof RetrySettings>[0]> = {}) {
26+
const onChange = vi.fn()
27+
act(() => {
28+
root.render(<RetrySettings retry={policy} disabled={false} onChange={onChange} {...props} />)
29+
})
30+
return { onChange }
31+
}
32+
33+
const field = (id: string) => container.querySelector<HTMLInputElement>(`#${id}`)
34+
35+
describe('RetrySettings', () => {
36+
it('leaves a configured value alone when the field is blurred untouched', () => {
37+
const { onChange } = renderSettings()
38+
const maxTries = field('block-retry-max-tries')!
39+
expect(maxTries.value).toBe('5')
40+
41+
act(() => {
42+
maxTries.dispatchEvent(new FocusEvent('focusout', { bubbles: true }))
43+
})
44+
45+
expect(onChange).not.toHaveBeenCalled()
46+
expect(field('block-retry-max-tries')!.value).toBe('5')
47+
})
48+
49+
it('renders only the switch while retry is off', () => {
50+
renderSettings({ retry: { ...policy, enabled: false } })
51+
52+
expect(field('block-retry-enabled')).not.toBeNull()
53+
expect(field('block-retry-max-tries')).toBeNull()
54+
})
55+
})

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/retry-settings/retry-settings.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ function RetryNumberField({
4848
const [draft, setDraft] = useState<string | null>(null)
4949

5050
const commit = () => {
51+
/** Untouched field: nothing was typed, so there is nothing to normalize or write. */
52+
if (draft === null) return
5153
const next = normalize(draft)
5254
setDraft(null)
5355
if (next !== value) onCommit(next)

0 commit comments

Comments
 (0)