Skip to content

Commit 1b54318

Browse files
committed
Fixes #118, timing issues with radio buttons and side-effects.
1 parent 07c4143 commit 1b54318

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ Headlines: Added, Changed, Deprecated, Removed, Fixed, Security
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Fixed
11+
12+
- `capture` and `restore` are now hoisted functions.
13+
- Fixed timing issues with radio buttons and validation with side-effects.
14+
815
## [0.8.4] - 2023-04-27
916

1017
### Fixed

src/lib/client/index.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,14 @@ function formEnhance<T extends AnyZodObject, M>(
12191219
);
12201220
}
12211221

1222+
function timingIssue(el: EventTarget | null) {
1223+
return (
1224+
el &&
1225+
(el instanceof HTMLSelectElement ||
1226+
(el instanceof HTMLInputElement && el.type == 'radio'))
1227+
);
1228+
}
1229+
12221230
// Add blur event, to check tainted
12231231
async function checkBlur(e: Event) {
12241232
if (
@@ -1228,8 +1236,8 @@ function formEnhance<T extends AnyZodObject, M>(
12281236
return;
12291237
}
12301238

1231-
// Select bindings have some timing issue, need to wait
1232-
if (e.target instanceof HTMLSelectElement) {
1239+
// Some form fields have some timing issue, need to wait
1240+
if (timingIssue(e.target)) {
12331241
await new Promise((r) => setTimeout(r, 0));
12341242
}
12351243

@@ -1251,8 +1259,8 @@ function formEnhance<T extends AnyZodObject, M>(
12511259
return;
12521260
}
12531261

1254-
// Select bindings have some timing issue, need to wait
1255-
if (e.target instanceof HTMLSelectElement) {
1262+
// Some form fields have some timing issue, need to wait
1263+
if (timingIssue(e.target)) {
12561264
await new Promise((r) => setTimeout(r, 0));
12571265
}
12581266

0 commit comments

Comments
 (0)