Fall back to the canonical URL for og:url

Merged
FK
20h ago
+63-6

og:url now falls back to the resolved canonical URL when it isn't set explicitly, exactly the way og:title and og:description already fall back to the page title and description. If canonical() was never called, og:url stays absent.

Head::defaults(fn (HeadBuilder $head) => $head->canonical()->og());

Why. Head::defaults() runs its callback immediately and freezes the result on the singleton manager. Under Octane one worker serves many requests, so a request-derived og:url — $head->og(url: request()->url()) in a service provider — is pinned by whichever request booted the worker: it boots on GET /pricing, and every later response ships <meta property="og:url" content="https://example.com/pricing"> until that worker recycles. It looks fine locally, where each request is its own process. Canonical already avoids this by resolving at render time, so routing og:url through it fixes the bug and reuses the mechanism instead of adding a second one.

Why the canonical URL rather than $request->url(). Falling back to the request URL would start emitting og:url for every app that calls Head::og(...), and would bypass the forceHttps and trailing-slash normalization already configured on canonical(). Reusing the canonical keeps og:url and <link rel="canonical"> in agreement by construction, and keeps the behavior opt-in through a call users already make.

An explicit og(url: ...) still wins. Resolution lives in render(), which feeds both toTags() and toHeadArray(), so the Inertia prop and Head::toArray() agree with the Blade output.

This does change output for apps already calling both canonical() and og(...) without a URL — they gain og:url. Per your note, that seems fine for a 0.x minor.