Skip to content

Commit e19733b

Browse files
committed
Hopefully fixed excessively deep infinity type instantiation on message helper.
1 parent 6323111 commit e19733b

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- `onUpdate` didn't cancel `applyAction` and `invalidateAll`.
13+
- Hopefully fixed excessively deep infinity type instantiation on `message` helper.
1314

1415
### Added
1516

src/index.test.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { setError, superValidate, defaultData } from '$lib/server';
1+
import {
2+
setError,
3+
superValidate,
4+
defaultData,
5+
setMessage
6+
} from '$lib/server';
27
import { assert, expect, test, describe } from 'vitest';
38
import { z, type AnyZodObject } from 'zod';
49
import _slugify from 'slugify';
@@ -160,12 +165,14 @@ test('FormData array data', async () => {
160165
});
161166

162167
test('Nullable values', async () => {
163-
const refinedSchema = z.object({
164-
scopeId: z.number().int().min(1),
165-
name: z.string().nullable()
166-
}).refine(data => data);
168+
const refinedSchema = z
169+
.object({
170+
scopeId: z.number().int().min(1),
171+
name: z.string().nullable()
172+
})
173+
.refine((data) => data);
167174

168-
const schema = refinedSchema._def.schema
175+
const schema = refinedSchema._def.schema;
169176

170177
const output = defaultData(schema);
171178
expect(output.scopeId).equals(0);
@@ -842,3 +849,27 @@ test('ZodObject defaults', async () => {
842849
}
843850
});
844851
});
852+
853+
test('setMessage and setError with refined schema', async () => {
854+
const schema = z
855+
.object({
856+
name: z.string(),
857+
id: z.number()
858+
})
859+
.refine((data) => data)
860+
.refine((data) => data);
861+
862+
const form = await superValidate({ name: '', id: 0 }, schema);
863+
assert(form.valid);
864+
expect(form.message).toBeUndefined();
865+
866+
setMessage(form, 'A message');
867+
expect(form.message).toEqual('A message');
868+
869+
expect(form.errors).toEqual({});
870+
setError(form, 'id', 'Id error');
871+
872+
expect(form.errors).toEqual({
873+
id: ['Id error']
874+
});
875+
});

src/lib/validate.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { clone } from './utils.js';
3939

4040
export { defaultData } from './schemaEntity.js';
4141

42-
export function message<T extends UnwrapEffects<AnyZodObject>, M>(
42+
export function message<T extends AnyZodObject, M>(
4343
form: Validation<T, M>,
4444
message: M,
4545
options?: {
@@ -58,8 +58,7 @@ export function message<T extends UnwrapEffects<AnyZodObject>, M>(
5858

5959
export const setMessage = message;
6060

61-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
62-
export function setError<T extends UnwrapEffects<AnyZodObject>>(
61+
export function setError<T extends AnyZodObject>(
6362
form: Validation<T, unknown>,
6463
path: keyof z.infer<T> | FieldPath<z.infer<T>> | [] | null,
6564
error: string | string[],
@@ -299,7 +298,9 @@ export async function superValidate<
299298
function tryParseSuperJson(data: FormData) {
300299
if (data.has('__superform_json')) {
301300
try {
302-
const output = parse(data.getAll('__superform_json').join('') ?? '');
301+
const output = parse(
302+
data.getAll('__superform_json').join('') ?? ''
303+
);
303304
if (typeof output === 'object') {
304305
return output as Record<string, unknown>;
305306
}

0 commit comments

Comments
 (0)