Skip to content

Commit 1e7ce0e

Browse files
committed
On a redirect response, form timers will not reset directly.
1 parent 05c1824 commit 1e7ce0e

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ 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-
## [1.0.0]
9-
10-
### Added
11-
12-
- New Superforms domain! https://superforms.rocks
8+
## [1.0.0-rc.5]
139

1410
### Fixed
1511

16-
- Fixed prototype mismatch for Zod schemas from different modules.
12+
- When a redirect response is received, form timers will not reset until after navigation or `onDestroy`.
13+
- Fixed prototype mismatch for Zod schemas in different modules.
1714
- SuperDebug color scheme updated. (Thanks to [gregorymcmillan](https://github.com/gregorymcmillan))
1815

1916
## [1.0.0-rc.4]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sveltekit-superforms",
3-
"version": "1.0.0",
3+
"version": "1.0.0-rc.5",
44
"author": "Andreas Söderlund <[email protected]> (https://blog.encodeart.dev)",
55
"description": "Making SvelteKit validation and displaying of forms easier than ever!",
66
"keywords": [

src/compare.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,20 @@ test('Checking side effects', () => {
386386
expect(hasEffects(social)).toStrictEqual(false);
387387
expect(hasEffects(refined)).toStrictEqual(true);
388388
});
389+
390+
test('Schema with array containing objects', async () => {
391+
const postSchema = z.object({
392+
questions: z
393+
.object({
394+
text: z.string(),
395+
generated: z.boolean()
396+
})
397+
.array()
398+
.min(1, {
399+
message: 'Must have at least one question'
400+
})
401+
});
402+
403+
const form = await superValidate(postSchema);
404+
expect(form.data).toStrictEqual({ questions: [] });
405+
});

src/lib/client/formEnhance.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { enhance, applyAction } from '$app/forms';
2-
import { invalidateAll } from '$app/navigation';
2+
import { afterNavigate, invalidateAll } from '$app/navigation';
33
import { page } from '$app/stores';
44
import type { ActionResult } from '@sveltejs/kit';
55
import { isElementInViewport, scrollToAndCenter } from './elements.js';
@@ -147,12 +147,21 @@ export function formEnhance<T extends AnyZodObject, M>(
147147
);
148148
}
149149

150+
afterNavigate((nav) => {
151+
if (nav.type == 'goto') {
152+
htmlForm.completed(true);
153+
}
154+
});
155+
150156
onDestroy(() => {
151157
ErrorTextEvents.forEach((formEl) =>
152158
ErrorTextEvents_removeErrorTextListeners(formEl)
153159
);
154160
ErrorTextEvents.clear();
161+
155162
formEl.removeEventListener('focusout', checkBlur);
163+
164+
htmlForm.completed(true);
156165
});
157166

158167
type ValidationResponse<
@@ -551,7 +560,10 @@ export function formEnhance<T extends AnyZodObject, M>(
551560
cancelFlash(options);
552561
}
553562

554-
htmlForm.completed(cancelled);
563+
// Redirect messages are handled in onDestroy and afterNavigate.
564+
if (result.type != 'redirect') {
565+
htmlForm.completed(cancelled);
566+
}
555567
}
556568

557569
return validationResponse;

0 commit comments

Comments
 (0)