File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,11 +6,17 @@ import { NO_VISITOR, pathSegments } from "../utils.ts";
66 * Disallows `on*` attributes for JSX components inside the
77 * `routes/` directory, as these components are rendered on the server.
88 *
9+ * It will also warn when passing a function as prop to a custom element,
10+ * as functions cannot be serialized to HTML on the server.
11+ *
912 * @example
1013 * ```tsx
1114 * // routes/index.ts
1215 * <button onClick={() => {}} />
1316 * // ^^^^^^^^^^^^^^^^^^ invalid handler
17+ *
18+ * <MyComponent handler={() => {}} />
19+ * // ^^^^^^^^^^^^^^^^^^ invalid handler
1420 * ```
1521 *
1622 * The `(_islands)` directory is excluded from this lint rule.
@@ -24,6 +30,7 @@ const MESSAGE = "Server components cannot install client side event handlers.";
2430const HINT =
2531 "Remove this property or turn the enclosing component into an island" ;
2632
33+ // Note: This selector will match any function passed as a prop to a custom element, not just event handlers.
2734const CUSTOM_ELEMENT_FN_EXPR_ATTR_SELECTOR =
2835 'JSXOpeningElement[name.type="JSXIdentifier"][name.name=/-/] > JSXAttribute[name.type="JSXIdentifier"]:has(> JSXExpressionContainer[expression.type=/^(FunctionExpression|ArrowFunctionExpression)$/])' ;
2936const HTML_ELEMENT_ON_ATTR_SELECTOR =
You can’t perform that action at this time.
0 commit comments