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

Pro Version: Error when hooking into dispatched event. #495

Open
GC-Max opened this issue Feb 3, 2025 · 2 comments
Open

Pro Version: Error when hooking into dispatched event. #495

GC-Max opened this issue Feb 3, 2025 · 2 comments

Comments

@GC-Max
Copy link

GC-Max commented Feb 3, 2025

When you hook into the below dispatched Livewire event Laravel errors.

overlay-component.js

closeActiveComponent() {
            Livewire.dispatch(`${this.type}.closing`, this.activeComponent);

The error happens because the dispatch event is sending a string back as a parameter instead of an array.

I have submitted this PR to fix it upstream livewire/livewire#9163 but if it could be fixed in the pro version that would be really appreciated as currently it is impossible to hook into the modal.closing event and know which component has just closed.

@PhiloNL
Copy link
Contributor

PhiloNL commented Feb 7, 2025

I'm not sure I follow. this.activeComponent is supposed to be a string. For example:

Livewire.on('modal.closing', (activeComponent) => {
    console.log(activeComponent); // c6accbe038dda1056e652fcc9c2ce1f1
})

The string is used internally to remove this specific instance from the state.

@GC-Max
Copy link
Author

GC-Max commented Feb 10, 2025

Yes the Javascript listener Livewire.on('modal.closing') expects and is able to handle receiving a string, but currently a PHP listener implementation will error if passed a string due to some unpacking happening in Livewire support files that expects there to be an array.

livewire/livewire#9163
Might give some more context to where this issue occurs in the PHP support files.

For example if you have this in your Livewire PHP class it would error before outputting the dd()

protected $listeners = ['modal.closing' => 'onModalClose'];

function onModalClose($activeComponent) {
     dd($activeComponent);
}

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