-
Notifications
You must be signed in to change notification settings - Fork 394
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
array mutations are not reactive in a custom lightning-datatable component. #4341
Comments
Thanks for filing! Do you have a repro you can share, e.g. using https://playground.lwc.dev? I tried to write a minimal repro, but my repro seems to be working as documented. If I use |
I worked with @roxanne-baker and we found a minimal repro. The key issue is: The parent passes in a <x-child data={data}></x-child> The parent makes @track data = [] The parent tries to update this.data.push(count++) However, the child doesn't update! The reason is that the child is using a setter to copy the @track state = { data: [] }
@api set data(data) {
this.state.data = [...data]
} <template for:each={state.data} for:item="datum">
<div key={datum}>{datum}</div>
</template> If the child were to avoid cloning the this.state.data = [...data]
+this.state.data = data ... then the reactivity works! This is actually longstanding LWC behavior, and goes back to at least LWC v3.0.0. The reason the child doesn't update is that the parent is passing in the reference to the It works if you don't clone the This is maybe not a bug in LWC, but it is certainly counter-intuitive behavior. |
Description
When using a custom type
lightning-datatable
, methods such aspush
,pop
, andsplice
on thedata
array are not reactive and do not cause a re-render on the custom type datatable element.Steps to Reproduce
An example of a custom type
lightning-datatable
is described in these developer docsAs described in the above linked docs, a custom type datatable consists of the following layers:
columns
anddata
are defined here)LightningDatatable
and declaresstatic customTypes
)When doing an array mutation method on the
data
in the wrapper layer, thedata
attribute is not reactive, even when using@track
.LWC version: 6.5.3
The text was updated successfully, but these errors were encountered: