tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.94k stars 250 forks source link

Octane - Wrong url #457

Closed tonysilva16 closed 3 years ago

tonysilva16 commented 3 years ago

Ziggy version

v1.4.0

Laravel version

v8.58

Description

ZiggyServiceProvider has a listener responsible to reset the state for current request and is setting the property generated to false, but the payload on the BladeRouteGenerator class is not changed so it returns the wrong url for the current request. This does not happen on 1.1.0, thats the version i am currently using

Ziggy call and context

//Octane listener
Event::listen(RequestReceived::class, function () {
    BladeRouteGenerator::$generated = false;
});

//BladeRouteGenerator, url it set on constructor
if (! static::$payload) {
    static::$payload = new Ziggy($group);
}

Ziggy configuration

Wrong url

Route definition

//
bakerkretzmar commented 3 years ago

Can you share more details about your setup and what exactly appears to be wrong? Does your app URL change from one request to the next?

tonysilva16 commented 3 years ago

The url does not change from one request to the next. I think the problem is that the url is only retrieved on the contructor of the ziggy class, and octane is not reseting that property (payload)

public function __construct($group = null, string $url = null)
{
    $this->group = $group;

    $this->url = rtrim($url ?? url('/'), '/');
    $this->port = parse_url($this->url)['port'] ?? null;

    $this->routes = $this->nameKeyedRoutes();
}
bakerkretzmar commented 3 years ago

Okay, can you please share more details about your specific situation though? If the app URL is the same on every request to your app, it shouldn't matter if Ziggy only checks the URL once since it'll be the same every time.

Please include your Ziggy configuration if possible.

tonysilva16 commented 3 years ago

Its a multi tenancy application, each tenant has a "subdomain"

{
    "url": "http://jVskklMMRjZOWjbkjQLs.dev.localhost",
    "port": null,
    "defaults": {
        "shopId": "zkGfyhccXCenYvCbJXHu"
    },
    "routes": {
        ........
    }
}

The url should be http://zkGfyhccXCenYvCbJXHu.dev.localhost

bakerkretzmar commented 3 years ago

Okay so your app's URL is not the same on every request 😅 I'll work on a fix for this, we can probably still get away with caching most of the payload but you're right the URL will have to not be persisted.

tonysilva16 commented 3 years ago

yeah, i see that know, i understood you were asking other thing... 🤣