Skip to content

Inertia Default Banner Component Does Not Show More Than Once #696

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

Closed
bricehartmann opened this issue Mar 1, 2021 · 5 comments
Closed

Comments

@bricehartmann
Copy link

  • Jetstream Version: 2.2.2
  • Jetstream Stack: Inertia
  • Uses Teams: no
  • Laravel Version: 8.29.0
  • PHP Version: 7.4.2
  • Database Driver & Version: mysql, 8.0.22

Description:

The default Banner component included with Jetstream will only show once if the same component is rendered after a form submission.

Steps To Reproduce:

  1. Spin up a new Laravel project with Jetstream (Inertia)
  2. Create a new component MyForm on the front end that submits to POST /my-form and drop it into your application
  3. Create a new route on the back end that flashes a banner to the session
Route::post('/my-form', function (\Illuminate\Http\Request $request) {
    $request->session()->flash('flash.banner', 'This is a banner');
    $request->session()->flash('flash.bannerStyle', 'success');

    return Inertia::render('MyFrom');
})->name('submit-my-form');
  1. Submit the form
  2. Dismiss the banner
  3. Submit the form again
  4. See that no new banner appears

Workaround:

Currently I am working around this by assigning a unique ID to each banner that is flashed with a watcher to reset the show flag in the Banner component.

In the Banner component, a new computed property:

id() {
  return this.$page.props.jetstream.flash?.bannerId || null
}

In the Banner component, a new watcher:

watch: {
  id(current, old) {
    if (current !== old) {
      this.show = true;
    }
  }
}

On the back end, any time I flash a banner to the session:

$request->session()->flash('flash.bannerId', uniqid());
@driesvints
Copy link
Member

Can you maybe create a repo that reproduces the bug so I can debug this more easily? Please commit your custom changes separately from the base skeleton.

@driesvints
Copy link
Member

Closing this issue because it's inactive, already solved, old or not relevant anymore. Feel free to reply if you're still experiencing this issue and we'll re-open this issue.

@mgsmus
Copy link
Contributor

mgsmus commented Jun 7, 2021

Thanks for the solution @bricehartmann I'm also dealing with that problem. To make things easier and prevent to re-render the component, I've added a timestamp value to HandleInertiaRequests::share() to make it available every component. I'm watching this value if I need:

const requestDate = computed(() => {
    return usePage().props.value.requestDate
})

watch(requestDate, (current, prev) => {
    if (current !== prev) {
        show.value = true
    }
})

@melih
Copy link

melih commented Jul 21, 2021

The problem is still there and needs to be solved. Thank you @bricehartmann.

@cwray-tech
Copy link

@driesvints this is still an issue. Where is the backend logic to the banner flash so I can make a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants