why would the internal x-effect have a timing to output an empty $data #4472
-
<section x-data="{section: {}}"
x-effect="console.log('section', $data);"
x-html="$data.section.html ? $data.section.html : $el.innerHTML"
>
<template
x-effect="console.log('template', $data); if ($data.main && $data.main.md) $data.section.html = $data.main.md.render($el.content.textContent)"
>
</template>
</section> console out
Why was the x-data output empty in line:3? |
Beta Was this translation helpful? Give feedback.
Answered by
SimoTod
Dec 9, 2024
Replies: 2 comments 6 replies
-
Because the element was rapidly added and removed and it resulted in the effect running once when the element was no in the page at all, so it didn't have a datastack. This code is really strange though... |
Beta Was this translation helpful? Give feedback.
4 replies
-
One way is to keep the template element, and another way is to safely remove an element managed by Alpine. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Everything mentioned in the effect will trigger the effect when changed so you should never set anything in qlan effect but always do it on the nextTick otherwise you get an effect that calls itslef. As mentioned above, your effect "deletes" the template itself which creates a leak where your template only exists in memory but is not linked to a component anymore so it will pront an empty data.
Not sure what the code is trying to achieve but ot looks like you could just use x-if.