[6.x] Refactor site route fallback#19241
Merged
Merged
Conversation
📚 Storybook previews@craftcms/cp — open Storybook No changed components detected in this Storybook. resources/js — open Storybook No changed components detected in this Storybook. |
Contributor
There was a problem hiding this comment.
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
DynamicRoutewith a focusedTemplateRoute, 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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