Skip to content

[13.x] Fix the previous route leaking into 404 requests under Octane - #62123

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
xurshudyan:router-reset-current-route
Oct 21, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
xurshudyan:router-reset-current-route

Conversation

@xurshudyan

Copy link
Copy Markdown
Contributor

The router sets $current when a route matches, but never clears it. So when the next request doesn't match anything, match() throws a 404 and $current still holds the previous request's route, along with its bound parameters.

With PHP-FPM this doesn't matter, but Octane reuses the router between requests:

// Request 1
GET /invoices/123   // "invoices.show", {invoice} bound to Alice's invoice

// Request 2, same worker
GET /missing-page   // 404

Route::currentRouteName(); // "invoices.show"
Route::input('invoice');   // Alice's invoice

Anything that reads the current route while the 404 is rendered or reported gets the previous request's data. For example, diglactic/laravel-breadcrumbs treats a missing current route as the 404 page, so under Octane the 404 page shows the previous request's breadcrumbs instead: https://github.com/diglactic/laravel-breadcrumbs/blob/main/src/Manager.php#L238-L244

This clears $current at the start of dispatch(), so a request that doesn't match a route has no current route, same as on PHP-FPM.

@taylorotwell
taylorotwell merged commit 835946c into laravel:13.x Oct 21, 2026
64 checks passed
@kichetof

Copy link
Copy Markdown
Contributor

Thanks for pointing this! I though it was Octane... I was able to fix my issue with middleware EnsureFeaturesAreActive, as the route exists, the name could be resolved from the router.

In case it can help someone, this is my code:

EnsureFeaturesAreActive::whenInactive(function (Request $request, array $features): never {
    /**
     * The breadcrumbs manager (`Diglactic\Breadcrumbs\Manager`) uses the router's current route
     * to resolve the page title. When a route is registered for a feature that is inactive, the manager
     * would otherwise generate a breadcrumb for that (now inaccessible) route, resulting in an
     * incorrect title. By clearing the protected `$current` property of the router, the manager falls
     * back to the built‑in 404 route (`['errors.404', []]`) and the breadcrumb title is hidden.
     */
    new ReflectionClass($router = app(Router::class))
        ->getProperty('current')
        ->setValue($router, null);

    abort(404);
});

binaryfire added a commit to hypervel/components that referenced this pull request Nov 1, 2026
Move coroutine-local current-route clearing into findRoute before Routing listeners run. Both dispatch and direct dispatchToRoute now clear stale route state, including failed route matching, without duplicate writes on ordinary dispatch.

Completes laravel/framework#62123 behavior compared at 13.x revision 5d7797528723107cd4f495326838a7d7d67fbb20 while retaining coroutine isolation.

Verified complete RoutingRouteTest and RouterExtensionTest files, full static analysis and formatting.
binaryfire added a commit to hypervel/components that referenced this pull request Nov 1, 2026
Keep current-route resetting in dispatch, matching laravel/framework#62123 at 13.x revision 5d7797528723107cd4f495326838a7d7d67fbb20, and mirror it in Hypervel's callback dispatch entrypoint. Do not reset in findRoute: a failed direct dispatchToRoute must preserve the active route as upstream does.

Both request entrypoints still clear stale state before Routing listeners, without adding a route stack or extra normal-path context writes. A real nested route test reproduces Router::input failing after a caught missing-route exception before this correction.

The complete RoutingRouteTest and RouterExtensionTest files, targeted source analysis and formatting pass.
albertcht pushed a commit to hypervel/routing that referenced this pull request Nov 1, 2026
Port laravel/framework#62123 from 835946cb1608a309be92141feae6be438639fbff, reconciled against the frozen 13.x source. A route miss must not expose the route from an earlier dispatch in the same coroutine.

Reset only the coroutine-local current route at the public dispatch boundary, preserving request isolation and dispatchToRoute customization. Port every upstream regression assertion; the test fails before the reset and the complete RoutingRouteTest passes afterward. Static analysis and formatting pass.
albertcht pushed a commit to hypervel/routing that referenced this pull request Nov 1, 2026
Move coroutine-local current-route clearing into findRoute before Routing listeners run. Both dispatch and direct dispatchToRoute now clear stale route state, including failed route matching, without duplicate writes on ordinary dispatch.

Completes laravel/framework#62123 behavior compared at 13.x revision 5d7797528723107cd4f495326838a7d7d67fbb20 while retaining coroutine isolation.

Verified complete RoutingRouteTest and RouterExtensionTest files, full static analysis and formatting.
albertcht pushed a commit to hypervel/routing that referenced this pull request Nov 1, 2026
Keep current-route resetting in dispatch, matching laravel/framework#62123 at 13.x revision 5d7797528723107cd4f495326838a7d7d67fbb20, and mirror it in Hypervel's callback dispatch entrypoint. Do not reset in findRoute: a failed direct dispatchToRoute must preserve the active route as upstream does.

Both request entrypoints still clear stale state before Routing listeners, without adding a route stack or extra normal-path context writes. A real nested route test reproduces Router::input failing after a caught missing-route exception before this correction.

The complete RoutingRouteTest and RouterExtensionTest files, targeted source analysis and formatting pass.
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