Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

URL Readability with InertiaJS #707

Open
muhammedkaraoglu opened this issue Jan 19, 2025 · 1 comment
Open

URL Readability with InertiaJS #707

muhammedkaraoglu opened this issue Jan 19, 2025 · 1 comment

Comments

@muhammedkaraoglu
Copy link

muhammedkaraoglu commented Jan 19, 2025

In my project using InertiaJS, I've noticed that square brackets ([]) in URLs are automatically encoded.

For example:
Original URL:
https://app.test/user?tableFilters[is_active][value]=1
Transformed URL:
https://app.test/user?tableFilters%5Bis_active%5D%5Bvalue%5D=1

While this doesn't cause any functional issues, it does reduce URL readability. Upon investigation,
I found this is related to the usage of $request->fullUrl() in Inertia's Responseclass.

I'd appreciate your thoughts on maintaining more readable URLs. Any insights from developers who have encountered similar situations or have experience with this would be valuable.

/**
     * Create an HTTP response that represents the object.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function toResponse($request)
    {
        $props = $this->resolveProperties($request, $this->props);

        $page = array_merge(
            [
                'component' => $this->component,
                'props' => $props,
           **this->     'url' => Str::start(Str::after($request->fullUrl(), $request->getSchemeAndHttpHost()), '/'),
                'version' => $this->version,
                'clearHistory' => $this->clearHistory,
                'encryptHistory' => $this->encryptHistory,
            ],
            $this->resolveMergeProps($request),
            $this->resolveDeferredProps($request),
            $this->resolveCacheDirections($request),
        );

        if ($request->header(Header::INERTIA)) {
            return new JsonResponse($page, 200, [Header::INERTIA => 'true']);
        }

        return ResponseFactory::view($this->rootView, $this->viewData + ['page' => $page]);
    }
@RobertBoes
Copy link
Contributor

It's a known issue; #592 (comment), #663
Ran into this myself too, but I don't think it'll be fixed in the foreseeable future.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants