Repository navigation
[4.x] Start fetching script modules before the page needs them - #10632
Merged
Merged
Conversation
calebporzio
force-pushed
the
claude/eager-script-module-delivery
branch
from
August 30, 2026 11:50
4923c9d to
5d7edb8
Compare
calebporzio
force-pushed
the
claude/defer-init-for-script-modules
branch
from
August 30, 2026 12:01
e2eddf0 to
e992667
Compare
calebporzio
force-pushed
the
claude/eager-script-module-delivery
branch
from
August 30, 2026 12:01
5d7edb8 to
b132eea
Compare
Suspending a component while its module loads is correct but leaves a window where the markup is visible and inert. Shrink that window to nearly nothing by starting fetches as early as the server knows they're coming: - Initial page loads (and lazy placeholders) inject a modulepreload link into the head, so the browser fetches the module while parsing HTML — long before Livewire boots and discovers it. wire:navigate carries the link along in its head merge for free. - Updates that mount new children announce them in a childScriptModules effect on the responding component, and the client starts those imports the moment the response arrives — before the morph that adds the children to the page. Both are pure latency optimizations: every component still imports and runs its own module when it mounts, so nothing here is load-bearing. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VxEoar4u3NVYop2jweewwf
calebporzio
force-pushed
the
claude/eager-script-module-delivery
branch
from
August 30, 2026 12:14
b132eea to
bfe96ca
Compare
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.
Follow-up to #10631, now rebased directly onto
4.x. That PR makes script-module loading correct — a component's tree suspends until its module has run. This one makes the suspended window invisible by starting fetches as early as the server knows they're coming. Everything here is a pure latency optimization: each component still imports and runs its own module when it mounts, so nothing in this PR is load-bearing — a missed preload just means a slightly longer window, never incorrect behavior.1.
modulepreloadlinks on initial page loadsSupportJsModules::dehydrate()already knows a mounting component's module URL and hash. On full-page renders it now registersthrough the existing rendered-assets head injection. The browser's preload scanner starts the fetch while parsing HTML — long before
livewire.jsboots, discovers the effect, and callsimport(). Today's waterfall (parse → boot → discover → fetch) becomes a parallel fetch, and the module is typically fetched and compiled beforeDOMContentLoaded, so the deferred window collapses to microtasks — resumed before first paint in the common case.Two extra wins for free:
scriptModuleeffect (the real view hasn't rendered), but the page render still knows the module is coming — the placeholder mount emits the preload link, so the module is warm by the time hydration needs it.wire:navigatemerges new head assets before initializing the new page, so preload links ride along automatically.Update requests are unaffected: the rendered-assets bucket is only injected into full-page HTML responses.
2.
childScriptModuleson update responsesFor children mounted by an update there's nothing to preload ahead of time — the response is the discovery. But the server knows which children with modules mounted during the request before the client sees any HTML. Each such mount is collected into a request-scoped static (cleared on
flush-state), and the responding component's dehydrate drains it into an effect:{ "childScriptModules": [{ "name": "testns::alpine-data", "hash": 3939658634 }] }The client fire-and-forgets
import()for each the moment the response arrives — overlapping the fetch with state sync and the morph, instead of starting it only when the child's root is encountered mid-morph. Lazy-hydrating components drain the same way, which also covers the nested case (a module component inside a lazy module component) that would otherwise fetch as a waterfall.Tests
UnitTest.php(6 tests): initial render injects the preload link into the head (asserted through the realRequestHandledinjection), no link for module-less components,childScriptModulesannounced when an update mounts a child and absent when it doesn't, the collector draining so the next update announces nothing, and lazy hydration announcing the modules of the children it mounts.BrowserTest.php: preload link present in the head on an initial render and on a page that only renders a lazy placeholder — both pages still load their modules and log no console errors.Full
SupportJsModulesbrowser suite (17) green on top of the defer branch.Notes from adversarial review: preload registration explicitly skips Livewire update requests (new children there are covered by
childScriptModules, and rendered assets would otherwise ride along in update payloads); and if a module file changes between a lazy placeholder's page render and its hydration, the two hashes produce two fetches — harmless, and inherent to hash-versioned URLs.🤖 Generated with Claude Code
https://claude.ai/code/session_01VxEoar4u3NVYop2jweewwf