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

Livewire: " Illuminate\Routing\RouteCollectionInterface is not instantiable", Session IDs not included in AJAX calls #15

Open
elrossco22 opened this issue Aug 15, 2023 · 24 comments

Comments

@elrossco22
Copy link

I'm trying to use this package (laravel-transsid) in conjunction with Livewire. I've followed the instructions in regards to adding the relevant service providers etc however when I call any of my Livewire components from within a blade template using the @livewire("componentName") syntax I get the below error

[Target [Illuminate\Routing\RouteCollectionInterface] is not instantiable while building [Livewire\Redirector, iMi\LaravelTransSid\UrlGeneratorService].]

Any help would be much appreciated

@amenk
Copy link
Member

amenk commented Aug 16, 2023

We don't use the module with Livewire so far. Can you try to dig this down for any more verbose error messages or use Xdebug to debug? If you found a fix, a pull request would be very appreciated.

@elrossco22
Copy link
Author

@amenk are you able to offer any help/guidance on the above. I've had a quick look however from what I can see Util::getParameterClassName($parameter) where $parameter->name ="routes" seems to return "Illuminate\Routing\RouteCollectionInterface" which then seems to traverse down through various functions within Application.php and Container.php before landing at the build() function and hitting an exception because it's not instantiable commentary for the function as below:

// If the type is not instantiable, the developer is attempting to resolve
// an abstract type such as an Interface or Abstract Class and there is
// no binding registered for the abstractions so we need to bail out.

@amenk
Copy link
Member

amenk commented Aug 17, 2023

You could try stackoverflow.com and / or provide a minimal reproducible example of the problem.

@elrossco22
Copy link
Author

@amenk minimal reproducible example of the problem as below:

1.) Clean install of Laravel
2.) Install Livewire via Composer
3.) Install iMi-digital/laravel-trannsid via Composer
4.) Create a test LiveWire Component (php artisan make:livewire TestComponent)
5.) Embed the test component within a Blade file that will be called from one of your routes (@livewire('TestComponent'))
6.) Hit the relevant url endpoint for the controller than returns the view file which contains the livewire embed

@elrossco22
Copy link
Author

@amenk a more helpful extract taken directly from my history

1.) composer create-project laravel/laravel=v9.4.0 test --prefer-dist
2.)composer require livewire/livewire
3.) composer require imi/laravel-transsid
4.) Edit config/app.php as per the imi/laravel-transsid instructions
5.) php artisan make:livewire ShowPosts
6.) edit resources/welcome/blade.php and add @livewire('show-posts') anywhere on the page
7.) php artisan serve
8.) hit the laravel home route with tour browser and the error will appear

@amenk
Copy link
Member

amenk commented Aug 17, 2023

Thank you very much for documenting ... we might look into it when we have time; we do provide paid services though which could speed up things...

@elrossco22
Copy link
Author

@amenk - could you please send me details r.e. paid service

@amenk
Copy link
Member

amenk commented Aug 17, 2023

@elrossco22 Please send me your contact to a.menk at imi.de

@amenk
Copy link
Member

amenk commented Aug 17, 2023

We will try to reproduce with Laravel 9

@amenk
Copy link
Member

amenk commented Aug 17, 2023

Reproduced on our system locally, trying to fix ...

@elrossco22
Copy link
Author

Thanks for the update @amenk - look forward to further updates on progress

@amenk
Copy link
Member

amenk commented Aug 18, 2023

We have a possible fix and push it soon to a dev branch for testing.

@amenk
Copy link
Member

amenk commented Aug 18, 2023

@elrossco22 please try requiring the version dev-15-livewire and see if it fixes your issue.

@elrossco22
Copy link
Author

Hey @amenk - I've had a quick look and this partially fixes the problem. That is to say that a blade template that features a LiveWire component will now render however LiveWire itself does not work.

LiveWire essentially uses Ajax to update the page data as user interacts - such as clicking a button etc. These interactions/requests are being fired however they do not take into consideration the SID in the url - I can see from my developer tools that LiveWire is posting to /livewire/message/ without any SID url param so is still reliant on the cookie to identify the session.

@elrossco22
Copy link
Author

elrossco22 commented Aug 18, 2023

Steps to reproduce as per our example above with the show-post component would be:

1.) Edit resources/views/welcome.blade.php and add @livewireScripts above the closing </body> tag
2.) Edit resources/views/welcome.blade.php and add @livewire('show-posts') in the main page div somewhere
3.) Edit resources/views/livewire/show-posts.blade.php and add <button type="button" wire:click="callFunction" class="btn btn-danger">Click Me</button>

If you now visit the page and click the button you will get an error as we never created the function named callFunction within out LivewWite Http Controller for ShowPosts. This is expectected! If you look in developer tools you will see that LiveWire is making it's Ajax request to /livewire/message/show-posts which does not have SID on the url and therefore the session is dropped

@amenk
Copy link
Member

amenk commented Aug 18, 2023

We might need to patch https://github.com/livewire/livewire/blob/7d3a57b3193299cf1a0639a3935c696f4da2cf92/js/connection/index.js#L46 and rebuild the livewire.js (we are using v2.12.6)

@amenk
Copy link
Member

amenk commented Aug 18, 2023

Actually there must be a way to extend the livewire request or payload without patching livewire :-)

@amenk
Copy link
Member

amenk commented Aug 18, 2023

livewire has a message.sent hook, but does not have a message.prepare hook or something similar :-(

@amenk
Copy link
Member

amenk commented Aug 18, 2023

we try the approach via a custom header: https://stackoverflow.com/a/72270789/288568

iSteuding added a commit that referenced this issue Aug 18, 2023
@amenk
Copy link
Member

amenk commented Aug 18, 2023

@elrossco22 try the latest push on the branch, pay attention to the "Livewire" section in the readme,

Too include Session Id's  use this script:

    <script type="text/javascript">
        document.addEventListener('livewire:load', function(event) {
            Livewire.addHeaders({
                'X-session': '{{ Session::getId() }}',
            })
        });
    </script>

@amenk amenk changed the title Target [Illuminate\Routing\RouteCollectionInterface] is not instantiable while building [Livewire\Redirector, iMi\LaravelTransSid\UrlGeneratorService]. Livewire: " Illuminate\Routing\RouteCollectionInterface is not instantiable", Session IDs not included in AJAX calls Aug 18, 2023
@elrossco22
Copy link
Author

@amenk - I will test more extensively over the weekend but on a first pass this looks like it may be working :)

@amenk
Copy link
Member

amenk commented Aug 21, 2023

@elrossco22 Did you have a change to test thoroughly? If so, we would merge the change and publish a new version.

amenk added a commit that referenced this issue Sep 8, 2023
#15 bind RouteCollectionInterface to fix livewire
@amenk
Copy link
Member

amenk commented Sep 8, 2023

Will release a new version, thanks for reporting and the support

@amenk
Copy link
Member

amenk commented Mar 20, 2024

@elrossco22 please contact me

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

2 participants