Repository navigation
v0.6.0 — Opt-in explicit reload for deferred components
Highlights
A new opt-in explicit reload for deferred components. By default a deferred fragment is fetched once and the placeholder is replaced away, leaving nothing to re-target. Defer::$reloadable keeps a re-fetchable wrapper in the DOM so a region can be reloaded later — the canonical "a form mutates data, reload the deferred list" pattern, plus reload from anywhere.
Opting in
#[Defer(name: 'todo-list', reloadable: true)]
// or
fc($render, defer: new Defer(name: 'todo-list', reloadable: true));Renders the placeholder with data-usephp-defer-name. usephp.js then swaps content inside that wrapper instead of replacing it away. Components that don't opt in are byte-identical to before (replaced on resolve). Independent of localCache / cacheControl.
Three triggers, one core API (usephp.js)
// 1. Imperative — from anywhere, no form required:
window.usePHP.reloadDefer(); // every reloadable region
window.usePHP.reloadDefer('todo-list'); // by defer name
window.usePHP.reloadDefer('/_defer/todo-list?p=2'); // by exact URL
// returns the number of regions reloaded (0 ⇒ nothing matched)<!-- 2. After a successful partial form submit (sees the mutated state) -->
<form data-usephp-form data-usephp-reload-defer="todo-list"> … </form>
<!-- 3. On click of any element outside a usephp form -->
<button data-usephp-reload-defer="todo-list">Refresh</button>
Attribute value is a space/comma-separated list of defer names (or exact URLs); empty reloads every reloadable region. Every reload busts both cache tiers for that URL first, so it always reflects current server state. Reload is decoupled from clearDeferCache() (invalidate-only).
Robustness
Per-wrapper single-flight + generation + AbortController: an unforced scan (processDeferred) yields to an in-flight fetch while a forced reloadDefer() supersedes it; a superseded response is discarded before placement and its request aborted, so a wrapper always settles on the newest requested state — no double placement, no stale-then-fresh flicker. The post-submit dispatch runs before the generic scan so the cache-busted fetch wins cleanly.
Docs & tests
- New "Explicit reload" / "明示的リロード" section in
README.md/README.ja.md. - Added tests: renderer markup contract (name attribute on/off, composes with
localCache),Defer/fc()propagation. Full suite (360 tests),php-cs-fixer, PHPStan (changed files) pass; JS syntax checked.
Full PR: #21 (Copilot review addressed: non-Element click-target guard; single-flight/supersede to remove the post-submit double-fetch and flicker).
Full Changelog: v0.5.0...v0.6.0