fix: allow string based event handlers in SSR (#1515)

This commit is contained in:
Marvin Hagemeister
2023-07-25 15:32:58 +02:00
committed by GitHub
parent 5e7d954e7c
commit 71c0434f46
6 changed files with 200 additions and 93 deletions
+16
View File
@@ -586,7 +586,23 @@ options.vnode = (vnode) => {
);
};
}
} else if (typeof vnode.type === "string" && vnode.props !== null) {
// Work around `preact/debug` string event handler error which
// errors when an event handler gets a string. This makes sense
// on the client where this is a common vector for XSS. On the
// server when the string was not created through concatenation
// it is fine. Internally, `preact/debug` only checks for the
// lowercase variant.
const props = vnode.props as Record<string, unknown>;
for (const key in props) {
const value = props[key];
if (key.startsWith("on") && typeof value === "string") {
delete props[key];
props["ON" + key.slice(2)] = value;
}
}
}
if (originalHook) originalHook(vnode);
};