-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: warn on invalid event handlers #12818
Conversation
🦋 Changeset detectedLatest commit: d5d1f46 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This doesn't apply to spread props, that can be a follow-up |
This made me realise something that is actually counterintuitive...technically upon opening the page count should be 3 because we are invoking something like this should probably work (i don't know how i would use this but it feels counter intuitive) |
We generate a derived in some cases to avoid repeating setup work. Our three options:
|
Demo
People coming from certain other frameworks, such as one that rhymes with 'foo', are often in the unfortunate habit of calling their event handlers inline, rather than simply passing a function:
We can catch a lot of these cases: if the handler is something like a call expression or an assignment expression, and the value isn't a function at the time we try to call it, print a warning. That's what this PR does.
What this doesn't capture is the case whereonclick
is a prop, becauseonclick={undefined}
is acceptable. Though as I type this it occurs to me that we can warn in case of a handler that is not a function and is also not nullish, as would be the case here:Will update the PR.doneBefore submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint