Skip to content

[6.x] Refactor site route fallback#19241

Merged
brandonkelly merged 3 commits into
6.xfrom
feature/site-route-fallback
Jul 13, 2026
Merged

[6.x] Refactor site route fallback#19241
brandonkelly merged 3 commits into
6.xfrom
feature/site-route-fallback

Conversation

@riasvdv

@riasvdv riasvdv commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Description

Refactors site request fallback handling around a single Laravel fallback route, keeps project and plugin routes compatible with route caching, removes recursive HTTP-kernel entry for previews and legacy routes, and moves final Yii URL-rule compatibility into adapter middleware.

Consolidates adjacent request middleware now that routing runs through the simplified pipeline.

The most important change here is that it removes re-entering the HTTP kernel, causing the whole middleware and HTTP stack to be ran again

BEFORE

Request
  │
  ▼
Laravel routes
  │
  ▼
Element middleware
  ├─ template ──────────> Response
  ├─ controller ────────> Response
  └─ action ────────────> Re-enter kernel
                              │
                              ▼
                         Yii fallback
                              │ 404
                              ▼
                       Public template
                              │
                              ▼
                         Response / 404


AFTER

Request
  │
  ▼
Laravel routes
  ├─ fixed core/plugin
  ├─ project-config
  └─ site fallback
          │
          ▼
       Element
          │ 404
          ▼
     Yii fallback
          │ 404
          ▼
   Public template
          │
          ▼
     Response / 404

@github-actions

github-actions Bot commented Jul 12, 2026

Copy link
Copy Markdown

📚 Storybook previews

@craftcms/cpopen Storybook

No changed components detected in this Storybook.

resources/jsopen Storybook

No changed components detected in this Storybook.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors site-request fallback handling to run through a single Laravel fallback route (instead of re-entering the HTTP kernel), with legacy Yii URL-rule compatibility handled via adapter middleware and related middleware pipeline simplifications.

Changes:

  • Introduces a Laravel Route::fallback() controller (SiteRouteController) for site element matching, and updates template routing to only run on that fallback.
  • Replaces DynamicRoute with a focused TemplateRoute, and updates legacy Yii rendering/dispatch to avoid re-entering the kernel.
  • Reworks token/preview handling so previews are prepared during token middleware, and consolidates powered-by/schema-version handling into existing middleware.

Reviewed changes

Copilot reviewed 38 out of 38 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
yii2-adapter/tests-laravel/Http/LegacyMiddlewareTest.php Adds coverage for legacy path normalization and middleware ordering (Yii fallback vs template fallback).
yii2-adapter/src/Yii2ServiceProvider.php Reorders/injects global & group middleware to support legacy path normalization and Yii site fallback.
yii2-adapter/src/Http/NormalizeLegacyPath.php New middleware that rewrites index.php?p=... requests without re-entering the app kernel.
yii2-adapter/src/Http/LegacyMiddleware.php Removes recursive kernel re-entry for legacy index.php?p= requests.
yii2-adapter/src/Http/HandleYiiSiteRouteFallback.php New middleware that runs Yii site URL-rule fallback on 404s from the Laravel site fallback route.
yii2-adapter/routes/web.php Adjusts legacy CP/action route registration to align with new fallback + route caching constraints.
yii2-adapter/legacy/web/Application.php Switches legacy rendering/dispatch to TemplateRoute and router dispatch (no kernel re-entry).
tests/Unit/Route/TemplateRouteTest.php Updates unit tests to use TemplateRoute instead of DynamicRoute.
tests/Unit/Plugin/Concerns/HasRoutesTest.php Adds assertions for route naming/serialization and route-cache behavior for plugin routes.
tests/Unit/Http/RequestMixinTest.php Updates getHadToken expectations to reflect validated-token semantics.
tests/TestClasses/TestPlugin/src/Controllers/HasRoutesActionController.php New invokable controller fixture for route serialization tests.
tests/TestClasses/TestPlugin/routes/actions.php Switches test action route from closure to controller for serialization support.
tests/Feature/Http/Middleware/SetHeadersTest.php Moves powered-by header assertions into SetHeaders middleware tests.
tests/Feature/Http/Middleware/SendPoweredByHeaderTest.php Removes tests for deleted SendPoweredByHeader middleware.
tests/Feature/Http/Middleware/HandleTokenRequestTest.php Expands coverage for token routing vs hidden action param behavior.
tests/Feature/Http/Middleware/HandleTemplateRequestTest.php Adds test ensuring fixed-route 404s aren’t replaced by template fallback.
tests/Feature/Http/Middleware/CheckSchemaVersionTest.php Removes tests for deleted CheckSchemaVersion middleware.
tests/Feature/Http/Middleware/CheckForUpdatesTest.php Adds schema-compat behavior tests now handled by CheckForUpdates.
tests/Feature/Http/Controllers/SiteRouteControllerTest.php Updates feature tests for new site fallback controller behavior and routing precedence.
tests/Feature/Http/Controllers/PreviewControllerTest.php Updates preview behavior expectations now that preview targets aren’t directly routable.
src/Route/TemplateRoute.php New dedicated template route handler.
src/Route/RouteServiceProvider.php Adjusts middleware stack and project route registration behavior for route caching.
src/Route/DynamicRoute.php Removes old dynamic route handler that re-entered the kernel.
src/Route/ControllerRoute.php Refactors controller route execution to dispatch via the current routed request.
src/Plugin/Concerns/HasRoutes.php Skips plugin route registration when routes are cached; adds naming prefix for site action routes.
src/Http/Routing/ActionRouteResolver.php Prevents action-param override when a token route has already been resolved.
src/Http/PreviewRequestPreparer.php New class to prepare preview placeholder elements during token handling.
src/Http/Mixins/RequestMixin.php Changes getHadToken() semantics to only reflect validated/handled tokens.
src/Http/Middleware/SetHeaders.php Moves powered-by header logic into SetHeaders and supports Symfony responses.
src/Http/Middleware/SendPoweredByHeader.php Removes powered-by header middleware (logic moved into SetHeaders).
src/Http/Middleware/HandleTokenRequest.php Updates token handling to prepare previews without kernel re-entry; adds route-resolved attribute.
src/Http/Middleware/HandleTemplateRequest.php Ensures template fallback only runs for the site fallback route.
src/Http/Middleware/CheckSchemaVersion.php Removes schema-version middleware (logic moved into CheckForUpdates).
src/Http/Middleware/CheckForUpdates.php Adds schema-version compatibility enforcement.
src/Http/Controllers/SiteRouteController.php Converts matched-element routing into the Laravel fallback controller path.
src/Http/Controllers/PreviewController.php Removes preview action endpoint; preview is now driven via token middleware flow.
routes/web.php Changes site fallback from abort(404) to SiteRouteController.
routes/actions.php Removes direct preview/preview action route from token-required routes.

Comment thread src/Http/Middleware/HandleTokenRequest.php
Comment thread src/Http/Middleware/SetHeaders.php Outdated
Comment thread yii2-adapter/src/Http/HandleYiiSiteRouteFallback.php Outdated
@riasvdv riasvdv requested a review from brandonkelly July 12, 2026 18:54
@riasvdv riasvdv marked this pull request as ready for review July 12, 2026 18:54
@brandonkelly brandonkelly merged commit 594a93a into 6.x Jul 13, 2026
25 checks passed
@brandonkelly brandonkelly deleted the feature/site-route-fallback branch July 13, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants