x-if evaluates content inside the template tag before the template tag itself #2296
Unanswered
arcanemachine
asked this question in
5. Bugs
Replies: 3 comments 1 reply
-
Not a fix for the existing bug but as a workaround you can prevent the error checking for the existence of the variable first |
Beta Was this translation helpful? Give feedback.
1 reply
-
Related: #2114 |
Beta Was this translation helpful? Give feedback.
0 replies
-
Looks like this got fixed by #2556. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a template that is only supposed to render if a
x-if
condition is met (it's also the index of an array containing a list of objects).Here's a basic example (Codepen version here):
The issue occurs when going from 1 to undefined. The logic inside the template is evaluated before evaluating the
x-if
statement in the template itself. Alpine attempts to find the value ofarr[current].a
before checking ifcurrent
exists as required by thex-if
statement.I'm certain this can be worked around easily. I just think it makes sense for the
x-if
statement to be evaluated before the logic inside the template.NOTE: This bug does not appear in v2.8.2, but does appear in 3.0.0
ANOTHER NOTE: If my
x-if
statement only checks forcurrent
, there is no error. However, this prevents me from accessing the 0th index of my array.Thanks for any help you can offer :)
Beta Was this translation helpful? Give feedback.
All reactions