Skip to content
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

[reactive-element] Leading double underscore in a property name is ignored #3690

Closed
jorg-vr opened this issue Feb 22, 2023 · 2 comments · Fixed by #3693
Closed

[reactive-element] Leading double underscore in a property name is ignored #3690

jorg-vr opened this issue Feb 22, 2023 · 2 comments · Fixed by #3693
Assignees
Labels

Comments

@jorg-vr
Copy link

jorg-vr commented Feb 22, 2023

Which package(s) are affected?

Lit Core (lit / lit-html / lit-element / reactive-element)

Description

Properties whose names start with __ are treated as the same property as the property without these underscores.

Use case:
I have an attribute foo that can be set by outside factors:

@property()
foo: string;

And an internal state variable __foo that is related, but should not override the externally set value

@property({state: true})
__foo: string;

when I update __foo, foo is also immediately updated, which should not be the case.

Reproduction

https://lit.dev/playground/#project=W3sibmFtZSI6InJlcHJvLnRzIiwiY29udGVudCI6ImltcG9ydCB7aHRtbCwgY3NzLCBMaXRFbGVtZW50fSBmcm9tICdsaXQnO1xuaW1wb3J0IHtjdXN0b21FbGVtZW50LCBwcm9wZXJ0eX0gZnJvbSAnbGl0L2RlY29yYXRvcnMuanMnO1xuXG5AY3VzdG9tRWxlbWVudCgneC1yZXBybycpXG5leHBvcnQgY2xhc3MgWFJlcHJvIGV4dGVuZHMgTGl0RWxlbWVudCB7XG4gIEBwcm9wZXJ0eSgpXG4gIGNvdW50ZXI6IG51bWJlcjtcblxuICBAcHJvcGVydHkoe3N0YXRlOiB0cnVlfSlcbiAgX19jb3VudGVyID0gMDtcblxuICByZW5kZXIoKSB7XG4gICAgcmV0dXJuIGh0bWxgXG4gICAgICA8cD5jb3VudGVyIGFuZCBfX2NvdW50ZXIgYXJlIGRpZmZlcmVudCB2YXJpYWJsZXMgYW5kIHNob3VsZCBhY3QgaW5kZXBlbmRlbnRseTo8L3A-XG4gICAgICA8YnV0dG9uIEBjbGljaz0ke3RoaXMuX29uQ2xpY2tCdXR0b259PkNsaWNrIG1lPC9idXR0b24-XG4gICAgICA8cD5jb3VudGVyID0gJHt0aGlzLmNvdW50ZXJ9PC9wPlxuICAgICAgPHA-X19jb3VudGVyID0gJHt0aGlzLl9fY291bnRlcn08L3A-XG4gICAgYDtcbiAgfVxuICBcbiAgX29uQ2xpY2tCdXR0b24oKSB7XG4gICAgdGhpcy5fX2NvdW50ZXIrKztcbiAgfVxufVxuIn0seyJuYW1lIjoiaW5kZXguaHRtbCIsImNvbnRlbnQiOiI8IURPQ1RZUEUgaHRtbD5cbjxoZWFkPlxuICA8c2NyaXB0IHR5cGU9XCJtb2R1bGVcIiBzcmM9XCIuL3JlcHJvLmpzXCI-PC9zY3JpcHQ-XG48L2hlYWQ-XG48Ym9keT5cbiAgPHgtcmVwcm8gY291bnRlcj01PjwveC1yZXBybz5cbjwvYm9keT5cbiJ9LHsibmFtZSI6InBhY2thZ2UuanNvbiIsImNvbnRlbnQiOiJ7XG4gIFwiZGVwZW5kZW5jaWVzXCI6IHtcbiAgICBcImxpdFwiOiBcIl4yLjAuMFwiLFxuICAgIFwiQGxpdC9yZWFjdGl2ZS1lbGVtZW50XCI6IFwiXjEuMC4wXCIsXG4gICAgXCJsaXQtZWxlbWVudFwiOiBcIl4zLjAuMFwiLFxuICAgIFwibGl0LWh0bWxcIjogXCJeMi4wLjBcIlxuICB9XG59IiwiaGlkZGVuIjp0cnVlfV0

Workaround

I have changed my internal variable name to use a single underscore (eg _foo instead of __foo)

Is this a regression?

No or unsure. This never worked, or I haven't tried before.

Affected versions

Using lit 2.6.1

Browser/OS/Node environment

Browser: Version 100.0 (64-bit)
OS: Linux mint 20.3

@bicknellr
Copy link
Member

Seems like this has been an issue since LitElement stopped using Polymer's property updating system:

const key = typeof name === 'symbol' ? Symbol() : `__${name}`;

@justinfagnani justinfagnani changed the title Leading double underscore in a property name is ignored [reactive-element] Leading double underscore in a property name is ignored May 10, 2023
@rictic
Copy link
Collaborator

rictic commented Oct 2, 2023

Fixed by #3693

@rictic rictic closed this as completed Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants