Skip to content

[4.x] TenancyUrlGenerator: override toRoute()#1439

Open
lukinovec wants to merge 4 commits intomasterfrom
override-toroute
Open

[4.x] TenancyUrlGenerator: override toRoute()#1439
lukinovec wants to merge 4 commits intomasterfrom
override-toroute

Conversation

@lukinovec
Copy link
Contributor

@lukinovec lukinovec commented Mar 9, 2026

This PR adds the toRoute() method override to TenancyUrlGenerator. toRoute() now attempts to find a tenant equivalent of the passed route (= a route with the same name as the passed one, but with the tenant prefix) and generates URL for the tenant route. This behavior can be bypassed using the bypass parameter, similarly to theroute() method override in TenancyUrlGenerator.

The primary reason for adding this is that Livewire v4 no longer uses the route() helper (which automatically prefixes the passed route name because of the override in TenancyUrlGenerator) in HandleRequests::getUpdateUri(). Now, it uses toRoute() (livewire/livewire@544aa3d#diff-e7609f8b0a60bde5a85067803d4e2f08f235c7cee9225a51ea67a85ff9a1d694R52), which doesn't automatically swap the route for a route with tenant prefix in tenant context. So for the Livewire integration to work with path identification, we need to override toRoute() as described.

The temporarySignedRoute() override got removed because temporarySignedRoute() calls route() under the hood, there's no need to specifically override temporarySignedRoute().

Note: Browsing old convos, it seems like the temporarySignedRoute() override was needed to make Livewire file uploads work with path identification, but it's not needed anymore. TenancyUrlGenerator had some changes since then, and now, I can't see the exact reason why we needed the override (temporarySignedRoute() uses route() under the hood, so the only thing that should really matter is overriding route()/toRoute()). It was likely a leftover from some older implementation.

The route() override got simplified. Since route() uses toRoute() under the hood, the route() override only has to have the prefixing logic. The rest gets delegated to toRoute().

Note: Even though we override toRoute() now which route() uses for generating the URLs, we still need to override route() for its $this->routes->getByName($name) call to receive the prefixed name. For example, if route() wasn't overridden, and we only had one route: tenant.foo (no central foo route), and we'd call route('foo'), we'd get an exception saying that route "foo" wasn't found, even if automatic route name prefixing was on and toRoute() was oveerridden. With the route() override, route('foo') acts as if we passed 'tenant.foo' instead of 'foo'.

Comments in TenancyUrlGenerator and UrlGeneratorBootstrapper got updated to be more accurate. All methods we intend to affect are listed in TenancyUrlGenerator's docblock.

Also update `route()` override since `parent::route()` calls `toRoute()` under the hood (similarly to how `parent::temporarySignedRoute()` calls `route()`)
@lukinovec lukinovec marked this pull request as ready for review March 9, 2026 12:39
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.10%. Comparing base (8f3ea62) to head (f0ff717).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1439      +/-   ##
============================================
+ Coverage     86.08%   86.10%   +0.02%     
  Complexity     1148     1148              
============================================
  Files           184      184              
  Lines          3363     3362       -1     
============================================
  Hits           2895     2895              
+ Misses          468      467       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The `toRoute()` and `route()` overrides cover `temporarySignedRoute())`, so we don't need to specifically override `temporarySIgnedRoute()` anymore. `route()` override got simplified since everything except for the name prefixing is delegated to the lower-level `toRoute()` method.
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.

1 participant