fix(notifications): guard against NaN/empty transitionDuration and transitionEasing in animate()#20057
Conversation
…ansitionEasing
When rapidly triggering actions that send notifications, Livewire commits
pile up. During these rapid commits, `getComputedStyle` can return empty
strings for `transitionDuration` and `transitionTimingFunction`, causing
`parseFloat('')` to yield `NaN` and leaving the easing as `""`.
Passing these to the Web Animations API throws:
TypeError: Failed to execute 'animate' on 'Element':
duration must be non-negative or auto
TypeError: Failed to execute 'animate' on 'Element':
Easing may not be the empty string
This crashes Alpine.js and blocks subsequent Livewire requests, causing
the UI to hang until a page reload.
Fix: apply fallback guards at the point of assignment in `init()`:
- `parseFloat(...) * 1000 || 0` for duration
- `transitionTimingFunction || 'ease'` for easing
3653811 to
8d6eddd
Compare
There was a problem hiding this comment.
This looks more like a fallback than a root-cause fix. I tried several ways to reproduce this locally, but couldn’t trigger the error naturally.
If you’re seeing this in a real app, could you share the exact reproduction steps, along with a screenshot or video of the error? That would help us understand what’s causing the invalid transition values and fix the underlying issue, instead of adding a guard that may hide it.
Thanks!
|
I tried to reproduce this with a fresh installation but wasn't able to. I then noticed that the Livewire JS files were outdated — after publishing them with |
What is the problem?
When rapidly triggering actions that send notifications (4–5 times in quick succession), Livewire commits pile up. During these rapid commits,
window.getComputedStyle(el).transitionDurationandtransitionTimingFunctioncan return empty strings — causingparseFloat('')to yieldNaNand leaving the easing as"".Passing these invalid values to the Web Animations API throws:
This crashes the Alpine.js component and blocks all subsequent Livewire requests, causing the UI to fully hang until a page reload.
What is the solution?
Apply fallback guards at the point of assignment in
init():parseFloat(...) * 1000 || 0— falls back to0when the computed value isNaNtransitionTimingFunction || 'ease'— falls back to'ease'when the computed value is an empty stringSteps to reproduce
TypeErrorin the browser console and the UI hanging