Skip to content

Conversation

@eslam-reda-div
Copy link
Contributor

Fixes an issue where Filament SPA mode fails when running on non PHP-FPM runtimes such as Laravel Octane (FrankenPHP, Swoole) and in containerized or load-balanced environments.


Issue

SPA mode relies on is_app_url() to determine whether a URL belongs to the application.
The previous implementation depended solely on request()->root(), which is not reliable in:

  • Octane runtimes (FrankenPHP / Swoole)
  • Reverse proxies and load balancers
  • Containers where the public app URL differs from the internal request root

This causes Filament to incorrectly treat internal URLs as external, breaking SPA navigation.


Change

Update is_app_url() to:

  • Prefer config('app.url') as the canonical application URL
  • Correctly handle relative URLs
  • Retain request()->root() as a safe fallback for backward compatibility
function is_app_url(string $url): bool
{
    if (str($url)->startsWith('/') && ! str($url)->startsWith('//')) {
        return true;
    }

    $appUrl = rtrim((string) config('app.url'), '/');

    return ($appUrl !== '' && str($url)->startsWith($appUrl))
        || rescue(fn () => str($url)->startsWith(request()->root()), false);
}

Impact

  • ✅ Fixes SPA mode on Octane (FrankenPHP, Swoole)
  • ✅ Works correctly behind proxies and in containers
  • ✅ No breaking changes
  • ✅ More predictable behavior across all runtimes

@github-project-automation github-project-automation bot moved this to Todo in Roadmap Jan 20, 2026
@danharrin danharrin added this to the v4 milestone Jan 20, 2026
@danharrin danharrin added bug Something isn't working pending review labels Jan 20, 2026
@github-project-automation github-project-automation bot moved this from Todo to In Progress in Roadmap Jan 21, 2026
@danharrin danharrin merged commit f9c9a67 into filamentphp:4.x Jan 21, 2026
23 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Roadmap Jan 21, 2026
@eslam-reda-div eslam-reda-div deleted the fix-spa-url-detection-temp branch January 21, 2026 12:17
@SerjoA
Copy link

SerjoA commented Jan 30, 2026

can this be merged to v3.3 also?

@SerjoA
Copy link

SerjoA commented Jan 30, 2026

this can be solved in filament 3.3 using trusted hosts and proxies in app middleware

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants