x-for does not update browser if element nested in a reusable component #3447
Unanswered
peterswords
asked this question in
5. Bugs
Replies: 3 comments 18 replies
-
Check with keys on the x-fors please. That is basically necessary for x-for and leaving it off will have strange behaviors This should work fine even going through nested contexts, so check that first. |
Beta Was this translation helpful? Give feedback.
10 replies
-
I feel like I'm experiencing an issue similar to this, but with |
Beta Was this translation helpful? Give feedback.
7 replies
-
Fix in #3504 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When I use
x-for
over an array, nested elements update correctly when the array changes. However, if those nested elements are inside a reusable component defined usingAlpine.data
, they do not update.In my real-world example these are complex nested components implementing expandable accordions and new data is fetched from a server. However, I've boiled it down to the bare essentials here so that the component definition is completely empty. A button click changes the content of the array from [x,y] to [a,b].
JSFiddle is here.
Initially the output looks like this, with two iterations over the array:
On clicking and replacing the array, the first iteration updates but the second does not:
EDIT:
If I parametrise the Alpine.data component with my data, everything works as expected:
Updated JSFiddle here.
This gives me a workaround I can live with. However, it forces me to choose the number of parameters that will be passed to the component, and I may have to repackage certain data used within it. In my real-world example, a generic accordion component doesn't really care about the sort of layout or associated data that will live inside it. It would be preferable if the nested components could see "through" the
Alpine.data
component to data contained in outer scopes. And it's also weird that the nested components can see outer data when first rendered, but don't see changes to those data.Beta Was this translation helpful? Give feedback.
All reactions