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
[lit-html] Add DEV_MODE error if duplicate attribute bindings are encountered #4523
Conversation
🦋 Changeset detectedLatest commit: d3d93a7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
📊 Tachometer Benchmark ResultsSummarynop-update
render
update
update-reflect
Resultsthis-change
render
update
update-reflect
this-change, tip-of-tree, previous-release
render
update
nop-update
this-change, tip-of-tree, previous-release
render
update
this-change, tip-of-tree, previous-release
render
update
update-reflect
|
The size of lit-html.js and lit-core.min.js are as expected. |
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.
lgtm!!
I think an error is correct here. The template will throw at rendering time anyway. |
Note: Converted to draft because this collapses duplicate attributes across individual tags which is invalid behavior. Added a test case: |
I fixed the implementation to be correct. Throw if there are attribute names that were not considered for template preparation (detects attribute mismatch). Adding the attribute that caused the attribute mismatch is going to be tricky as duplicate attribute names can exist across multiple tags. I think this implementation is strictly an improvement, and we provide the template in the error that caused the issue. This will reduce debugging time for user's who encounter this error. |
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.
Ooohhh very clever to check that we've consumed everything from attrNames
!
Co-authored-by: Steve Orvell <sorvell@google.com>
Fixes: #4194
Context
A lot of the context is in the issue, but in short, if an attribute binding is duplicated, such as in the following example:
The result is that Lit parts get out of sync with the values (because attributes are de-duped by the browser).
Fix
I've implemented this as a DEV_MODE error, but I'm open to making it a DEV_MODE warning.
The following template:
<input ?disabled=${true} ?disabled=${false}>
, will throw: