Skip to content

fix: resolve Livewire.interceptMessage race condition in schemas package - #19073

Closed
olipayne wants to merge 1 commit into
filamentphp:5.xfrom
olipayne:fix/livewire-interceptmessage-race-condition
Closed

fix: resolve Livewire.interceptMessage race condition in schemas package#19073
olipayne wants to merge 1 commit into
filamentphp:5.xfrom
olipayne:fix/livewire-interceptmessage-race-condition

Conversation

@olipayne

Copy link
Copy Markdown
Contributor

Problem

Users experienced Livewire.interceptMessage is not a function JavaScript 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 an alpine:init event listener. The alpine:init event can fire before Livewire is fully initialized, especially when:

  • Filament's scripts load before Livewire's scripts
  • Alpine is loaded separately via CDN
  • Custom bundle configurations reorder script loading

This created a race condition where window.Livewire was undefined when the interceptor tried to register.

Solution

Changed the event listener from alpine:init to livewire:init in packages/schemas/resources/js/index.js.

The livewire:init event is fired as the first line of Livewire's start() function, guaranteeing that window.Livewire exists before any code inside the listener executes.

Changes

  • Source: packages/schemas/resources/js/index.js - Moved Livewire.interceptMessage() to livewire:init listener
  • Compiled: packages/schemas/dist/index.js - Rebuilt assets
  • Test: tests/src/Schemas/JavaScriptEventListenerTest.php - Added regression test

Testing

  • ✅ Added regression test with 3 test cases and 7 assertions
  • ✅ Test verifies Livewire.interceptMessage() is in livewire:init listener
  • ✅ Test ensures it's NOT in alpine:init listener
  • ✅ All schemas package tests pass (67 tests, 113 assertions)

Closes

Fixes #19070

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.
@danharrin danharrin added the bug Something isn't working label Jan 24, 2026
@danharrin danharrin added this to the v5 milestone Jan 24, 2026
@danharrin

Copy link
Copy Markdown
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.

@danharrin danharrin closed this Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants