Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[reactive-element] Reactive properties don't handle private names properly #4998

@justinfagnani

Description

@justinfagnani

Which package(s) are affected?

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

Description

When a standard private field is decorated with @state() the name of the field is something like '#foo', which requestUpdate() then uses to get the current value of the field, here:

const newValue = this[name as keyof this];

this['#foo'] does not return the value of this.#foo, it is an entirely different property, so the change detection logic fails, specifically when changing value from undefined (since the new value will appear to be undefined and so no change is detected.

A fix would be to allow requestUpdate() to take the new value as a parameter instead of looking it up by name.

Reproduction

None yet. The playground doesn't support standard accessors yet.

Workaround

Use non-standard TypeScript private fields.

Is this a regression?

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

Affected versions

3.x

Browser/OS/Node environment

All

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions