-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
improve warning when extra event listeners (fix #1001) #1005
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cfd25da
feat(runtime-core): improve extra events warning
ddfe349
refactor(runtime-core): accurate event casing in warning
ab473b2
chore: remove unused import
7c31618
chore: add tests
e434fba
chore: resolve conflicts
fbaf57a
refactor(runtime-core): accurate event casing in warning
ecb8334
chore: remove unused import
4949369
chore: add tests
00a2fda
refactor(runtime-core): attr getter is dev only
5d66103
chore: merge
778786a
Merge branch 'master' into dev/warn_extra_events
f0a8317
chore: break long string
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,10 +70,19 @@ export function renderComponentRoot( | |
} else { | ||
// functional | ||
const render = Component as FunctionalComponent | ||
// in dev, mark attrs accessed if optional props (attrs === props) | ||
if (__DEV__ && attrs === props) { | ||
markAttrsAccessed() | ||
} | ||
result = normalizeVNode( | ||
render.length > 1 | ||
? render(props, { | ||
attrs, | ||
get attrs() { | ||
if (__DEV__ && attrs !== props) { | ||
markAttrsAccessed() | ||
} | ||
return attrs | ||
}, | ||
slots, | ||
emit | ||
}) | ||
|
@@ -107,12 +116,34 @@ export function renderComponentRoot( | |
root.patchFlag |= PatchFlags.FULL_PROPS | ||
} | ||
} else if (__DEV__ && !accessedAttrs && root.type !== Comment) { | ||
warn( | ||
`Extraneous non-props attributes (` + | ||
`${Object.keys(attrs).join(', ')}) ` + | ||
`were passed to component but could not be automatically inherited ` + | ||
`because component renders fragment or text root nodes.` | ||
) | ||
const allAttrs = Object.keys(attrs) | ||
const eventAttrs: string[] = [] | ||
const extraAttrs: string[] = [] | ||
for (let i = 0, l = allAttrs.length; i < l; i++) { | ||
const key = allAttrs[i] | ||
if (isOn(key)) { | ||
// remove `on`, lowercase first letter to reflect event casing accurately | ||
eventAttrs.push(key[2].toLowerCase() + key.slice(3)) | ||
} else { | ||
extraAttrs.push(key) | ||
} | ||
} | ||
if (extraAttrs.length) { | ||
warn( | ||
`Extraneous non-props attributes (` + | ||
`${extraAttrs.join(', ')}) ` + | ||
`were passed to component but could not be automatically inherited ` + | ||
`because component renders fragment or text root nodes.` | ||
) | ||
} | ||
if (eventAttrs.length) { | ||
warn( | ||
`Extraneous non-emits event listeners (` + | ||
`${eventAttrs.join(', ')}) ` + | ||
`were passed to component but could not be automatically inherited ` + | ||
`because component renders fragment or text root nodes.` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
) | ||
} | ||
} | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should only make
attrs
a getter in dev.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed. Is it okay, though, to use
__DEV__
with a ternary to achieve that?