diff --git a/.changeset/funny-seas-begin.md b/.changeset/funny-seas-begin.md new file mode 100644 index 000000000000..c1e631b59974 --- /dev/null +++ b/.changeset/funny-seas-begin.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: preserve `this` when invoking standard validator diff --git a/packages/kit/src/runtime/app/server/remote/shared.js b/packages/kit/src/runtime/app/server/remote/shared.js index c078d290db6f..388f699bef0a 100644 --- a/packages/kit/src/runtime/app/server/remote/shared.js +++ b/packages/kit/src/runtime/app/server/remote/shared.js @@ -30,9 +30,8 @@ export function create_validator(validate_or_fn, maybe_fn) { return async (arg) => { // Get event before async validation to ensure it's available in server environments without AsyncLocalStorage, too const { event, state } = get_request_store(); - const validate = validate_or_fn['~standard'].validate; - - const result = await validate(arg); + // access property and call method in one go to preserve potential this context + const result = await validate_or_fn['~standard'].validate(arg); // if the `issues` field exists, the validation failed if (result.issues) {