Skip to content

Commit e598981

Browse files
committed
docs: add note about warning function props
1 parent 6aa8619 commit e598981

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

packages/lint/src/rules/server-event-handlers.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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.";
2430
const 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.
2734
const CUSTOM_ELEMENT_FN_EXPR_ATTR_SELECTOR =
2835
'JSXOpeningElement[name.type="JSXIdentifier"][name.name=/-/] > JSXAttribute[name.type="JSXIdentifier"]:has(> JSXExpressionContainer[expression.type=/^(FunctionExpression|ArrowFunctionExpression)$/])';
2936
const HTML_ELEMENT_ON_ATTR_SELECTOR =

0 commit comments

Comments
 (0)