livewire / livewire

A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
MIT License
22.19k stars 1.53k forks source link

Unable to emit up $refresh when model being pushed to @stack('modals') #2290

Closed toxifiedmatrix closed 3 years ago

toxifiedmatrix commented 3 years ago

Description

I am successfully being able to emit up $refresh from the livewire child component to the livewire parent component. In this case, I have a parent component i.e. user data table and a child component i.e. user edit modal. When ever I update the user data, I emit up $refresh, so the table refreshes and displays the updated data. But in this case I am pushing the modal to the @stack('modals'). In this scenario, the $refresh isn't working.

Exact steps to reproduce

Push the modal to the @stack('modals'), as soon as I do that, I am unable to emit up $refresh and display the updated data.

Stripped-down, copy-pastable code snippets

App\Http\Livewire\UserController.php

protected $listeners = ['sectionRefresh' => '$refresh'];

App\Http\Livewire\Modal\UserEditModal.php

public function saveUser()
    {
        $this->validate();
        $this->validate([
            'user.email' => 'unique:users,email,'.$this->user->id,
        ]);
        $this->user->roles()->sync($this->role);
        $this->user->save();
        $this->showUserManagementModal = false;

        $this->dispatchBrowserEvent('notify', $this->user->name.' Updated Successfully');

        $this->emitUp('sectionRefresh');
    }

Context

joshhanley commented 3 years ago

@toxifiedmatrix I'm guessing the reason is because, when you push to the stack, it means the modal component is now outside your main component and instead appended to the end of the page.

So emitUp won't work as there is no component around the outside of the modal. Maybe just try emit, or emitTo and specify the component name.

But I'm only guessing, if that doesn't work, can you provide your layout file, and blade files for your components so we can have a proper look?

Hope this helps!

toxifiedmatrix commented 3 years ago

Yes you are really a great help! just emit works perfectly, its working fine as of now, thanks alot!

squishythejellyfish commented 3 years ago

👋 Oh Hi! I'm Squishy, the friendly jellyfish that manages Livewire issues.

I see this issue has been closed.

Here in the Livewire repo, we have an "issues can be closed guilt-free and without explanation" policy.

If for ANY reason you think this issue hasn't been resolved, PLEASE feel empowered to re-open it.

Re-opening actually helps us track which issues are a priority.

Reply "REOPEN" to this comment and we'll happily re-open it for you!

(More info on this philosophy here: https://twitter.com/calebporzio/status/1321864801295978497)

tawalbe commented 3 years ago

ddf