bvfi-dev's avatar

Collapsing a <div> section is laggy only in the initialization

I have a pretty simple form. Basically I have a status select dropdown and I want an animation when the status is a certain ID:

What happens here is basically when the status is NOT "Coming Soon" There are 2 dropdowns next to each other -> Category + Status dropdowns

When the Status is changed from anything -> "Coming Soon" the Category dropdown takes the whole row, the status disappears from next to the category and a new section appears. This new section is the "Coming Soon" section.

THE ISSUE I HAVE: When I first enter the page and change the status from lets say Active -> Coming Soon, the Coming Soon section appears almost instantly, as if lagging (Instead of the animations I have set it). Then I switch it from Coming Soon -> Active, the animation is smooth. If I then without refreshing switch it again from Active -> Coming Soon the animation is smooth and how I want it (Which DOESNT happen the first time this is done). So, this only happens when the page INITIALLY LOADS and the status is switched to Coming soon. Then the rest of the workflow is smooth. I cant for the love of god figure out whats wrong and why it only happens the first time, I have tried removing classes, changing input elements, wrapping in , nothing helps. And I know it is probably something stupid or simple I have missed, but I cant find it.

EDIT: I have uploaded a video: Streamable URL

0 likes
3 replies
valentin_vranic's avatar

Hey. Idk what could cause you an issue, bcs I've tried with your provided code, and the transition seems to me that takes effect on the first attempt after loading the page.

Please provide the versions of your stack. Laravel, livewire

bvfi-dev's avatar

I use last Laravel 11 version, Livewire 3 installed with Jetstream 5. But this shouldn't influence the AlpineJS. I noticed that it kind of starts smooth, but then suddenly instantly opens down. I uploaded a video, at 0:15 I refresh the page:

Streamable URL

I cant figure out why it happens consistently only on the first try on the page, how can I even debug this, its literally just JS harmonicas.

bvfi-dev's avatar
bvfi-dev
OP
Best Answer
Level 3

I updated the child Blade component root to have:

<div wire:key="edit-course-form-root" class="grid grid-cols-1 gap-6"
		x-data="{
			statusId: $wire.entangle('courseForm.status_id'),
			ztComing: {{ (int) $ztCourseComingSoon }},
			hydrated: false,
			isComingSoon(){ return Number(this.statusId) === this.ztComing; }
		}" x-init="$nextTick(() => { hydrated = true })">

And then changed the Coming Soon section to have:

<div x-cloak x-show="hydrated && isComingSoon()"

Now when the Model has status Coming soon and I load the page, the Coming Soon section appears smoothly with animation, but changing it to Active still does the same, so Im thinking it has something to do with changing the Status for the first time. What I did was remove the .live from the select in the section when Coming Soon was active and that fixed the issue...Im not sure why .live would cause it to behave that way. I technically dont need the live for the edit form, but I need it for my create form.

Please or to participate in this conversation.