Repository navigation
[4.x] Defer Alpine init until component modules load - #10619
Closed
calebporzio wants to merge 3 commits into
Closed
calebporzio wants to merge 3 commits into
calebporzio wants to merge 3 commits into
Conversation
Co-authored-by: Josh Hanley <[email protected]>
Co-authored-by: Josh Hanley <[email protected]>
Co-authored-by: Josh Hanley <[email protected]>
This was referenced Aug 28, 2026
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.
Rebased and reorganized replacement for #10295. The core approach and original regression coverage were developed with @joshhanley, who is credited on each commit.
Problem
Alpine.data()in its co-located script module, but Alpine evaluates the component'sx-datafirst. The browser logsAlpine Expression Error: ... is not defined, and the dependent UI is blank or non-interactive. This can happen on initial render, dynamic mounts, lazy hydration, islands, andwire:navigate.scriptModuleeffect starts an asynchronousimport(), while Alpine continues its synchronousstart()/initTree()traversal. The async registration loses that race.Solution
Keep
Livewire.start()synchronous and defer Alpine initialization only for a component whose script module is pending.The trade-off is a brief uninitialized state for only the affected component while its module downloads. That is narrower than making Livewire's global boot and message lifecycles asynchronous.
Alternatives considered
Alpine.data()into a global@assets/alpine:initscript or use an inlinex-dataobject. This avoids a framework contribution, but sacrifices co-location and does not make component-local modules correctly ordered.Verification
DUSK_SERVE_PORT=8011 vendor/bin/phpunit --configuration phpunit.xml.dist src/Features/SupportJsModules/BrowserTest.php— 13 tests, 46 assertionsnpm run test:run— 110 passed, 1 skippednpm run build— both Livewire bundles built successfully4.xrendered a blank status with two Alpine reference errors; this branch rendersAlpine data loadedwith no console errorsContext: #10295, #9861, discussions #9591, #9737, and #9830.