Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Shared props issues #29

Open
jaulz opened this issue Oct 4, 2022 · 4 comments
Open

Shared props issues #29

jaulz opened this issue Oct 4, 2022 · 4 comments

Comments

@jaulz
Copy link

jaulz commented Oct 4, 2022

While using your great package (thanks!), I noticed that the approach sometimes does not generate the desired output. For example, my HandleInertiaRequests middleware returns the breadcrumbs for every request but when I render a modal the breadcrumbs of the background page are obviously not correct because the route of the modal is used. In general, I think as soon as the shared props are different for modal and background page it causes issues. Should the middleware hence run twice? Not sure how Laravel will behave then so it's more like an architectural question.

@jaulz
Copy link
Author

jaulz commented Oct 4, 2022

Maybe it's also worth storing the baseRequest in the request itself so it can be retrieved from within the HandleInertiaRequests and the developer can decide which requests he needs.

@jenky
Copy link

jenky commented Dec 30, 2022

I also getting problems with shared props today. For example, form.errors when using useForm is not working because the errors prop returns in page props instead of modal.props

@epalmans
Copy link

epalmans commented Jan 3, 2023

there might be a side-effect, but it may help to derive the baseRoute - or actually its URL - from the referer header.
E.g. In my HandleInertiaRequests I'm using a macro on the Request class to then check the route; either being the one accessed directly, or the one in the "backdrop" used as baseRoute:

public function share(Request $request)
{
    return array_merge(parent::share($request),
        $request->isRouteOrReferer('admin.*') ? [
            // your data to pass in for this specific route-pattern
        ] : [],

    );
}

the macro:

use Illuminate\Http\Request;

Request::macro('isRouteOrReferer', function (String $routePattern) {
    if ($this->routeIs($routePattern)) {
        return true;
    }

    if ($refererUrl = $this->header('referer')) {
        $routeName = rescue(
            fn () => app('router')->getRoutes()->match(app('request')->create($refererUrl, 'GET'))->getName(),
            report: false
        );

        return Str::is($routePattern, $routeName);
    }

    return false;
});

@dellow
Copy link

dellow commented Jan 14, 2023

I'm also having the same issue. My component error props are intercepted by the base route not the rendered modal. If I remove the baseRoute it works just fine.

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

No branches or pull requests

4 participants