konshensx16 / mercure-chat-tutorial

Final code for the tutorial posted on youtube on Making a Chat application using Symfony 5, Mercure & Vue.
35 stars 14 forks source link

after pressing enter, the message is displayed two times #5

Open ecarsmd opened 4 years ago

ecarsmd commented 4 years ago

when I send the "post" message, it is displayed two times as in the following video - https://www.youtube.com/watch?v=pdMh7e4kO-M do you know why this happens?

e1sep0 commented 3 years ago

I have same problem, help please

konshensx16 commented 3 years ago

Hello there, I'm so sorry I did not see the original post by @ecarsmd i just got notified now about this.

Please make sure that you are using the version that I used in the video, because they changed so much with the newer versions and they also removed the mechanism that sends the messages to a single target which is what is causing the message to be displayed twice.

The mercure version that I used was: ^0.2.3 The binary can be downloaded from here: https://github.com/dunglas/mercure/releases/tag/v0.10.0

If the problem persists please let me know

e1sep0 commented 3 years ago

Hello, I took last mercure bundle: "symfony/mercure-bundle": "^0.2.5", I made some changes in Message controller:

        $update = new Update(
            [
                sprintf("/conversations/%s", $conversation->getId()),
                sprintf("/conversations/%s", $recipient->getUser()->getUsername()),
            ],
            $messageSerialized
        );

And changes in Index Controller:

$token = (new Builder())
            ->withClaim('mercure', ['subscribe' => [sprintf("/conversations/%s", $username)]])
            ->getToken(
                new Sha256(),
                new Key($this->getParameter('mercure_secret_key'))
            )
        ;

Recipient get One message, But Sender views self message twice: image

Maybe some problem in Vue files ? Thank you. mercury bundle 0.2.3 i can`t install unfortunately

e1sep0 commented 3 years ago

I can leave only one topic in MessageController, but then updates only Left side (Recent)

e1sep0 commented 3 years ago

I decided this problem, installed mercury 0.3.0. Thank you. But got new one( Sometimes page redirects after message sending, do you know why and how to fix it ? Thanks a lot )

konshensx16 commented 3 years ago

Hm that is really weird, which page do you get redirected to ? Also do you get redirect in the Vue app ? like the url changes ? or just when you take a look at the XHR request is says 302 redirected ?

e1sep0 commented 3 years ago

After first message in chat pages refreshes, in profiler i see 301 redirect: image After this refresh chat works without this refreshing. Maybe something with auth?

ecarsmd commented 3 years ago

I decided this problem, installed mercury 0.3.0. Thank you. But got new one( Sometimes page redirects after message sending, do you know why and how to fix it ? Thanks a lot )

mercure-bundle 0.2.5 and mercure 0.3.0 ?

e1sep0 commented 3 years ago

I decided this problem, installed mercury 0.3.0. Thank you. But got new one( Sometimes page redirects after message sending, do you know why and how to fix it ? Thanks a lot )

mercure-bundle 0.2.5 and mercure 0.3.0 ?

"symfony/mercure": "^0.3",
"symfony/mercure-bundle": "^0.2.5",
ecarsmd commented 3 years ago

I decided this problem, installed mercury 0.3.0. Thank you. But got new one( Sometimes page redirects after message sending, do you know why and how to fix it ? Thanks a lot )

mercure-bundle 0.2.5 and mercure 0.3.0 ?

"symfony/mercure": "^0.3",
"symfony/mercure-bundle": "^0.2.5",

to me the problem persists (

e1sep0 commented 3 years ago

to me the problem persists (

I found solution: in assets/js/components/Right/Input.vue change line: in form <form action="#"> add onsubmit event and remove action: <form onsubmit="event.preventDefault();">