eidellev / inertiajs-adonisjs

279 stars 17 forks source link

Flash messages issue #32

Closed jakemake closed 3 years ago

jakemake commented 3 years ago

Hi! I'm tryin to configure snackbar notifications using Adonisjs session flash, after creating new row through the POST method

I set session flash message then redirect to another path in adonis controller but my vue app can't see any changes in $page.props.[shared data name]

My adonisjs controller: "create" method: image

"list" method: image

In chrome dev tools network tab i can see server responds properly with shared data (with flash messages) image

Seems like inertia adapter or inertia self not updating $page variable

start/inertia.ts image

i set watcher in Vue 2 like this (in layout component) image additionally i put console log to watcher and watcher's value staying changeless.

Also i tried to set preserveState but no result

But ihave several cases, where notifications works properly,

  1. when i use manual request $inertia.delete() with method spoofing and redirecting to same page it works image

When i'm staying on same page for example "/admin/reservation/list" and trying to create new "reservation" using modal dialog

eidellev commented 3 years ago

Hi @jakemake It looks like you did everything right as far as I can tell (at least from the server's perspective). In fact I did something similar in my own app and it worked, although I'm using React instead of Vue.

Looking at the official docs for the Vue 2 adapter, I think you need to access flash messages this way:

{{ $page.props.flash.message }}

Let me know if it worked for you :-)

jakemake commented 3 years ago

@eidellev thanks again for your quick reply )) Seems like it's a Vue watchers bug or something 🤷‍♂️. Works unstable, and hard to find out issue pattern. But i managed to use you suggestion with little tweaks and it works. Sorry for disturbing and thanks =)