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

Flash message doesn't show in livewire without reloading #161

Open
codebyshami opened this issue Nov 17, 2023 · 12 comments
Open

Flash message doesn't show in livewire without reloading #161

codebyshami opened this issue Nov 17, 2023 · 12 comments
Labels
findapr help wanted Extra attention is needed

Comments

@codebyshami
Copy link

  public function bell()
    {
        $this->count += 1;
        flash()->addInfo('Your information has been saved and a confirmation email has been sent.');
    }

This flash message doesn't show up until I reload the page
If I reload the page then what's is the point of using livewire

@codebyshami
Copy link
Author

no updates yet for livewire v3, experiencing the same problem

Did you found any solution or any alternative?

@mr-wolf-gb
Copy link

mr-wolf-gb commented Dec 6, 2023

I made this solution until update come for supporting livewire 3 dispatch logic :

1. add an envent listener in app.layout.blade.php at the bottom of body

<script type="text/javascript">
    window.addEventListener('php-flasher-js', event => {
        flasher.render(JSON.parse(event.detail[0]));
    });
</script>

2. add Helper function

use Livewire\Component;

if (!function_exists('flashDispatch')) {
    function flashDispatch(Component $component, $message = null, $type = 'success', array $options = array(), array $stamps = array())
    {
        $flasher = flash($message, $type, $options, $stamps);
        $component->dispatch('php-flasher-js', json_encode(app('flasher.response_manager')->render([],'array')));
        return $flasher;
    }
}

3. in component use like this

<?php

namespace App\Livewire;

use Livewire\Component;

class Test extends Component
{
    public function test() {
        flashDispatch($this, "working fine !", 'warning');
    }

    public function render()
    {
        return view('livewire.test');
    }
}

@yoeunes
Copy link
Member

yoeunes commented Dec 9, 2023

Hello guys,

I've just released PHPFlasher v1.15.5 with support for Livewire v3. It's not fully tested yet, so I'd appreciate if you could test it in your environment. Please update using:

composer require php-flasher/flasher-laravel ^1.15.5

Let me know if there are any issues. Your feedback will help in deciding whether to close this issue.

Thanks!
Younes

@mr-wolf-gb
Copy link

Hello guys,

I've just released PHPFlasher v1.15.5 with support for Livewire v3. It's not fully tested yet, so I'd appreciate if you could test it in your environment. Please update using:

composer require php-flasher/flasher-laravel ^1.15.5

Let me know if there are any issues. Your feedback will help in deciding whether to close this issue.

Thanks! Younes

Good job, thanks

@mr-wolf-gb
Copy link

Hello guys,

I've just released PHPFlasher v1.15.5 with support for Livewire v3. It's not fully tested yet, so I'd appreciate if you could test it in your environment. Please update using:

composer require php-flasher/flasher-laravel ^1.15.5

Let me know if there are any issues. Your feedback will help in deciding whether to close this issue.

Thanks! Younes

there is a problem that drove me crazy 😄 , inside component i have this function :

public function resetForum()
{
    $this->dispatch('refreshListOpened');
    flash()->addSuccess("Done !");
}

in this form the dispatched event not received in the other component, but when i comment the flash line :

public function resetForum()
{
    $this->dispatch('refreshListOpened');
    //flash()->addSuccess("Done !");
}

the dispatched event received fine 😄

@yoeunes
Copy link
Member

yoeunes commented Dec 11, 2023

Hi @gaiththewolf i just released v1.15.7, this should fix the problem

@donnebanget
Copy link

Hi @gaiththewolf i just released v1.15.7, this should fix the problem

Hi @yoeunes when using default => 'flasher' that working fine, but when using notyf as default when change page that using wire:navigate notyf not showing.

Example:

  1. User edit they profile and save (notyf showing)
  2. User back to dashboard
  3. User back to edit profile and save (notyf not showing) but when reload page and save again notyf showing
Dashboard-Garuda-Indonesia-Virtual-Group.mp4

@yoeunes
Copy link
Member

yoeunes commented Dec 13, 2023

Hello @donnebanget, can you create a repo on github so i can reproduce the issue ?

@donnebanget
Copy link

Hello @donnebanget, can you create a repo on github so i can reproduce the issue ?

Hi @yoeunes

please check this:
https://github.com/donnebanget/notyf-laravel

@yoeunes
Copy link
Member

yoeunes commented Dec 16, 2023

Hello @donnebanget,

Can you please upgrade to version v1.15.8, as this should fix the issue. Additionally, this version includes an upgrade for the flasher assets to v1.3.2.

If you're not using a CDN, please ensure to manually copy the new assets into your public/ folder. This step is crucial for the changes to take effect properly.

Best regards,
Younes

@donnebanget
Copy link

donnebanget commented Dec 18, 2023

Hello @donnebanget,

Can you please upgrade to version v1.15.8, as this should fix the issue. Additionally, this version includes an upgrade for the flasher assets to v1.3.2.

If you're not using a CDN, please ensure to manually copy the new assets into your public/ folder. This step is crucial for the changes to take effect properly.

Best regards, Younes

Hello @yoeunes , sorry for late respond.

I have upgrade to the v.1.15.8 and i back to use cdn but this issue still persist when using notyf. when using default flasher its okay before and after upgrade.

Notes: i re-clone repository than composer upgrade

Thanks for the awesome project!

Update:
I forgot to change in config that require asset v.1.3.2 now is working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
findapr help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants
@mr-wolf-gb @yoeunes @donnebanget @codebyshami and others