fix: preserve `this` when invoking standard validator (#14943)
authorMira Šerý <athes01@gmail.com>
Thu, 20 Nov 2025 08:53:38 +0000 (09:53 +0100)
committerGitHub <noreply@github.com>
Thu, 20 Nov 2025 08:53:38 +0000 (09:53 +0100)
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.

.changeset/funny-seas-begin.md [new file with mode: 0644]
packages/kit/src/runtime/app/server/remote/shared.js

diff --git a/.changeset/funny-seas-begin.md b/.changeset/funny-seas-begin.md
new file mode 100644 (file)
index 0000000..c1e631b
--- /dev/null
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+fix: preserve `this` when invoking standard validator
index c078d290db6ffd7c95bfd33c802221271ea7219a..388f699bef0acfd7f1d2be50484c9d96fcebaadc 100644 (file)
@@ -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) {