nextTick with x-show sometimes fires too early, before DOM attibutes are updated.
#4636
Unanswered
virtuallyunknown
asked this question in
5. Bugs
Replies: 1 comment 3 replies
-
|
I'd suggest a different approach entirely, and use |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Greetings.
I've been struggling to figure out exactly why this is happening, but please consider the following example:
https://codesandbox.io/p/sandbox/3ptp79
Here I have 3
<button>s, each one being atooltipAlpine component (sorry if the terminology isn't quite right). When we focus them with theTABkey, we call theshowmethod which switches the component state totrue, which in turn toggles the visibility of their child<section>s.Then inside the very same
showmethod, we proceed to callnextTickin order to give Alpine time to make all the DOM updates, with the hopes that thestyle.displayvalue of the<section>element will not be'none'anymore.This is a very simplified demo and I'm only logging the value of
style.displayfor debugging purposes, but my real world usage involves callinggetBoundingClientRectmethod on this element, and that will only work properly if the element is visible on the screen (notdisplay: none).The problem is that this doesn't work as expected, and on a seemingly random basis, I get to see that
style.displayis stillnone, even after thenextTick.On Firefox, I am getting
nonelogged almost 90% of the times, and therequestAnimationFrametest I've added never throws.On Chrome, it's the opposite. I am getting empty string logged (expected behavior) most of the time, but occasionally
requestAnimationFramewould throw.Any advice on how to deal with this issue?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions