inertia-laravel icon indicating copy to clipboard operation
inertia-laravel copied to clipboard

Error in view data / url prop

Open kimhf opened this issue 3 years ago • 18 comments
trafficstars

Currently if the project has the base url localhost/test and we navigate to some/sub/page the result is a url change to localhost/test/test/some/sub/page in the brower by inertiajs. This url no longer matches the route we are currently at.

The issue seems to be that a path as part of the base url is not handled correctly.

This line in \Inertia\Response causes the issue.

'url' => $request->getBaseUrl().$request->getRequestUri(),

kimhf avatar Jan 27 '22 15:01 kimhf

I have created a pull request #360 with a possible solution to this issue.

kimhf avatar Jan 27 '22 16:01 kimhf

This looks like a duplicate of #236

rhysemmerson avatar Jan 28 '22 09:01 rhysemmerson

I do not believe this is a duplicate of #236, but a solution might solve both issues.

kimhf avatar Jan 31 '22 08:01 kimhf

@claudiodekker seems this was introduced in https://github.com/inertiajs/inertia-laravel/pull/333

If I am not mistaken this anyway shouldn't be Inertia's job. The behavior before was just fine and the issue which lead to the PR should be solvable by e.g. setting root in the NGINX config (untested).

NickSdot avatar Feb 05 '22 13:02 NickSdot

It should in my opinion be Inertia's job to handle different server configurations. The problem as far as I can see is that #333 is the wrong fix for the problem. At least in my case where I'm setting RewriteBase /to/project in .htaccess

The combination of $request->getBaseUrl() + $request->getRequestUri() generates a invalid url with that server config. Looking at how fullUrl() / getUri() builds the url $request->getBaseUrl() + $request->getPathInfo() + $queryString (or fullUrl()) seems to be the right approach and should handle more server configurations.

It seems to me that $request->getBaseUrl() + $request->getRequestUri() are not intended to be combined together in that way.

kimhf avatar Feb 06 '22 13:02 kimhf

Thanks @kimhf. I can't wait this gets released.

I have just started using inertia a couple days ago. This will solve my problem with a project in subfolder.

lotsofbytes avatar Feb 08 '22 17:02 lotsofbytes

I hope this commit will be merged soon because it is seemed to be that this will solve my problem too.

w99910 avatar Feb 13 '22 17:02 w99910

Hope this gets fixed soon, it fixed my issue as well. ✊

juancarlos-ctg avatar Apr 15 '22 19:04 juancarlos-ctg

also interested in a fix, at the moment I have to mess with the toResponse function in /vendor/inertiajs/inertia-laravel/src/Response.php

qbuache avatar May 04 '22 11:05 qbuache

I am also interested in this fix! Currently unable to update a site to Laravel 9 because of this issue.

romanmartushev avatar May 05 '22 13:05 romanmartushev

This also fixed my issue. Hope it gets merged soon.

dopesky avatar May 12 '22 08:05 dopesky

Holy sh**! I lost one week of my life because of this bug! I tested 3 different web server (apache, nginx, IIS) to finally find this bug!

lucraraujo avatar Jun 03 '22 21:06 lucraraujo

I noticed this issue after submitting issue #421 and proposing PR #422

I spent 4 hours this afternoon before finding this bug!

also interested in a fix, at the moment I have to mess with the toResponse function in /vendor/inertiajs/inertia-laravel/src/Response.php

This is how I've dealt with it too in the meantime.

andrew1601 avatar Jun 23 '22 22:06 andrew1601

This fixed my problem too, I'm glad I found the solution I was struggling since the beggining of this week. Thanks

Pachekoko avatar Jul 14 '22 17:07 Pachekoko

I spent a lot of time trying to fix this thing in my nginx conf, until I started looking at Laravel & InertiaJs packages to understand the source of the duplication. Definitely this patch is the right solution for the problem. I can't wait to see this merged (in the mean time, I'm going to production with a fork ¯_(ツ)_/¯).

CristianSitov avatar Aug 29 '22 07:08 CristianSitov

I can't wait to see this merged!!!!!!!!

sinceow avatar Sep 19 '22 08:09 sinceow

Awaiting the merge, almost a year, gosh

kentchang84 avatar Dec 08 '22 02:12 kentchang84

I have same issue so i downloaded the package and edited it localy.

Actually i also edited svelte package too.

raghed-kahil avatar Nov 17 '23 15:11 raghed-kahil