Skip to content

feat(panel): ship a dedicated middleware group (spec 0059)#2580

Merged
glennjacobs merged 2 commits into
2.xfrom
panel/dedicated-middleware-group
Jul 22, 2026
Merged

feat(panel): ship a dedicated middleware group (spec 0059)#2580
glennjacobs merged 2 commits into
2.xfrom
panel/dedicated-middleware-group

Conversation

@glennjacobs

Copy link
Copy Markdown
Contributor

Problem

The panel already ships its own Inertia middleware (HandlePanelInertiaRequests), but it wrapped its routes in the host app's web middleware group (route_middleware => ['web']).

That couples the panel to whatever the consuming app has bolted onto web. The concrete failure: installing Inertia in the host app registers App\Http\Middleware\HandleInertiaRequests into the web group, which then double-stacks with the panel's own Inertia middleware on every panel route — leaking the app's shared props into panel responses, conflicting on the root view, and (most damaging) disagreeing on the asset version(), which triggers spurious 409 full-page reloads. Any other web customisation (locale, tenancy, extra auth) rode along too.

Change

Register a dedicated lunar.panel middleware group from the framework web primitives and default route_middleware to it:

  • EncryptCookies, AddQueuedCookiesToResponse, StartSession, ShareErrorsFromSession, PreventRequestForgery, SubstituteBindings
  • These read app-level config (session.php, cookie domain, CSRF except paths), so session/cookie/CSRF behaviour is preserved — only app-appended middleware is dropped.
  • Mirrors how the Filament admin owns its own stack.
  • The config seam is preserved: a developer who wants the host web stack (or a bespoke one) still overrides lunar.panel.route_middleware.

Migration note

The default value of lunar.panel.route_middleware changes ['web']['lunar.panel']. Transparent for apps on defaults (strictly a fix). An app that has published the panel config keeps its existing ['web'] value until it re-publishes — recommended path is to re-publish or set ['lunar.panel'] manually. Not a code-level break; no Rector rule needed.

Tests

  • PanelServiceProviderTest: asserts the new default, the exact group membership, and that panel.dashboard gathers HandlePanelInertiaRequests but not web.
  • Full panel suite green (724 passed); Pint + PHPStan (level 0) clean.

Spec: specs/0059-panel-middleware-group.md (status accepted).

🤖 Generated with Claude Code

The panel wrapped its routes in the host app's `web` middleware group.
A downstream app that installs Inertia registers its own
HandleInertiaRequests into `web`, which then double-stacks with the
panel's HandlePanelInertiaRequests -- leaking the app's shared props
into panel responses and triggering spurious 409 asset reloads. Any
other host `web` customisation applied to panel routes too.

Register a `lunar.panel` middleware group from the framework `web`
primitives (cookies, session, CSRF, bindings, share-errors) and default
`route_middleware` to it. Session/cookie/CSRF config is still read from
the app; only app-appended middleware is dropped. The config seam is
preserved for anyone who wants the host stack back.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Laravel 13 renamed ValidateCsrfToken to PreventRequestForgery. Hardcoding
the new name broke the L12 CI matrix (PHPStan "class not found" + panel
suite). Resolve the class name at runtime via class_exists() with string
literals, so both versions get a real class and PHPStan does not flag a
missing class reference.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@glennjacobs
glennjacobs merged commit 5981b1a into 2.x Jul 22, 2026
22 checks passed
@glennjacobs
glennjacobs deleted the panel/dedicated-middleware-group branch July 22, 2026 11:44
@github-project-automation github-project-automation Bot moved this from Todo to Done in Roadmap Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant