fix: resolve Livewire.interceptMessage race condition in schemas package - #19073
Closed
olipayne wants to merge 1 commit into
Closed
fix: resolve Livewire.interceptMessage race condition in schemas package#19073olipayne wants to merge 1 commit into
olipayne wants to merge 1 commit into
Conversation
Fixes filamentphp#19070 The bug occurred because Livewire.interceptMessage() was called inside an alpine:init event listener. The alpine:init event fires before Livewire is fully initialized, causing a race condition where window.Livewire might be undefined when Filament's scripts load before Livewire's scripts. Changed the event listener from alpine:init to livewire:init to ensure Livewire is fully loaded before calling its API methods. Added regression test to prevent future occurrences.
Member
|
Original issue is not reproducible, and the fix doesn't make sense really. Alpine is not loaded from a CDN as your PR description mentions, Alpine is bundled within the Livewire JS. AI-generated changes still need to be tested and validated before submission. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Users experienced
Livewire.interceptMessage is not a functionJavaScript errors when using Filament 5.1 with Livewire 4. This prevented modal actions (Edit/Delete/Create) from working in tables and relation managers.Root Cause
The schemas package called
Livewire.interceptMessage()inside analpine:initevent listener. Thealpine:initevent can fire before Livewire is fully initialized, especially when:This created a race condition where
window.Livewirewas undefined when the interceptor tried to register.Solution
Changed the event listener from
alpine:inittolivewire:initinpackages/schemas/resources/js/index.js.The
livewire:initevent is fired as the first line of Livewire'sstart()function, guaranteeing thatwindow.Livewireexists before any code inside the listener executes.Changes
packages/schemas/resources/js/index.js- MovedLivewire.interceptMessage()tolivewire:initlistenerpackages/schemas/dist/index.js- Rebuilt assetstests/src/Schemas/JavaScriptEventListenerTest.php- Added regression testTesting
Livewire.interceptMessage()is inlivewire:initlisteneralpine:initlistenerCloses
Fixes #19070