Skip to content

x-data within x-for loop — inconsistently updating #3372

Answered by ekwoka
njpanderson asked this question in 1. Help
Discussion options

You must be logged in to vote

The issue has to do with how the parent scopes are propagated downwards to the children.

Since the x-for isn't rerendering the looped item due to the key matching, the scope still contains the old item scope.

For this contrived example, the fix is simple: have the replaced items have new keys (the id field).

this should also be satisfactory for any real use case as you wouldn't realistically be replacing the array with items with the same keys but different data.

If you did, then you need a more complex key to handle differentiation for the diffing algo.

So I would say the behavior itself is exactly in spec with what someone aware of the technical implementation of alpine and how the keye…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by njpanderson
Comment options

You must be logged in to vote
7 replies
@ekwoka
Comment options

@SimoTod
Comment options

SimoTod Jan 6, 2023
Collaborator

@SimoTod
Comment options

SimoTod Jan 6, 2023
Collaborator

@njpanderson
Comment options

@billksun
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants