Skip to content

Commit 540a4ee

Browse files
authored
fix: preserve this when invoking standard validator (#14943)
The validate function call currently loses the dynamic this binding. Thus, if a standard validator's validate function is a class method that makes use of this, it will be undefined, as is the case when using TypeBox's standard schema adapter.
1 parent d8c8bd7 commit 540a4ee

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

.changeset/funny-seas-begin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: preserve `this` when invoking standard validator

packages/kit/src/runtime/app/server/remote/shared.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ export function create_validator(validate_or_fn, maybe_fn) {
3030
return async (arg) => {
3131
// Get event before async validation to ensure it's available in server environments without AsyncLocalStorage, too
3232
const { event, state } = get_request_store();
33-
const validate = validate_or_fn['~standard'].validate;
34-
35-
const result = await validate(arg);
33+
// access property and call method in one go to preserve potential this context
34+
const result = await validate_or_fn['~standard'].validate(arg);
3635

3736
// if the `issues` field exists, the validation failed
3837
if (result.issues) {

0 commit comments

Comments
 (0)