Repository navigation
v0.4.0 - Component-side defer declaration
Defer metadata moves from the PSX call site onto the component itself, and usephp compile auto-discovers every endpoint. This is a breaking change to the defer API — the magic defer / fallback PSX attributes are gone and replaced with explicit wrapper components.
Breaking: defer config lives on the component (#17)
Before (v0.3.0):
<UserHeader defer="user-header" fallback={<HeaderSkeleton />} />
$app->registerDeferred(
name: 'user-header',
component: 'App\\Components\\Psx\\UserHeader',
cacheControl: 'private, no-store',
);After (v0.4.0): split into a base component and a deferred wrapper that carries the Defer config.
{/* UserHeaderDeferred.psx — the wrapper */}
use Polidog\UsePhp\Component\Defer;
use function Polidog\UsePhp\Runtime\fc;
return fc(
fn(array $props) => <UserHeader />,
defer: new Defer(name: 'user-header', cacheControl: 'private, no-store'),
);
{/* Page.psx — fallback is a normal prop */}
<UserHeaderDeferred fallback={<HeaderSkeleton />} />
// No registerDeferred() call — loadComponentManifest() picks up the
// deferred-manifest.php sidecar that `usephp compile` writes.
$app->loadComponentManifest($manifestPath);Class components use the same idea via #[Defer(...)]:
#[Component(name: 'UserHeaderDeferred')]
#[Defer(name: 'user-header', cacheControl: 'private, no-store')]
final class UserHeaderDeferred extends BaseComponent
{
public function render(): Element { /* the endpoint-side content */ }
}
$app->register(UserHeaderDeferred::class); // endpoint + PSX placeholder both wiredWhy
- Single source of truth for each defer endpoint — name and cache policy travel with the component, no parallel
registerDeferred()list to keep in sync. usephp compileenumerates every endpoint at build time, so the framework can auto-register them; manual wiring goes away.- Removes the PSX parser's special-casing of
deferandfallback— every prop is now a normal prop.
Migration
- For each component that was used with
defer="…"in PSX, create a wrapper component:- Closure form: new
.psxreturningfc(fn(\$props) => <Base />, defer: new Defer(name: '…', cacheControl: '…')). - Class form: new
BaseComponentsubclass annotated with#[Defer(name: '…', cacheControl: '…')].
- Closure form: new
- Replace
<Base defer="…" fallback={…} />with<BaseDeferred fallback={…} />at every call site. - Drop the corresponding
\$app->registerDeferred(...)calls. - Re-run
usephp compileso the newdeferred-manifest.phpsidecar is generated.
Other changes
fc()now returns an invokableFunctionComponent(still callable, exposesdeferfor inspection).loadComponentManifest()also picks updeferred-manifest.phpnext tomanifest.php.Defer::buildPlaceholder()is the shared materialiser used by both the closure wrapper and the class-component PSX bridge.
Full Changelog: v0.3.0...v0.4.0