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

Toasts do not work when used alongside vue-turbolinks after first page change #225

Open
Arns opened this issue Jun 2, 2022 · 1 comment

Comments

@Arns
Copy link

Arns commented Jun 2, 2022

I'm using Vue with Vue Turbolinks and Vue Toasted. When I refresh completely, the toasts work fine. When I refresh, then switch pages one or more times, the toasts do not work. I've narrowed it down to being an issue due to running alongside vue-turbolinks. I believe turbo links replaces the element each navigation, so perhaps that is causing issues with toasted?

Expected Behavior: Toasts show even after all turbolinks navigations

Here is my app initialization code:

import TurbolinksAdapter from 'vue-turbolinks'
import Vue from 'vue/dist/vue.esm'
import Toasted from 'vue-toasted'

document.addEventListener('turbolinks:load', () => {
  axios.defaults.headers.common['X-CSRF-Token'] = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
  axios.defaults.headers.common['Content-Type'] = 'application/json';
  axios.defaults.headers.common['Accept'] = 'application/json';

  const app = new Vue({
    el: '#vue-app',
    data: function() {
      return {
    },
    components: { 

    }
  })

  Vue.use(Toasted)

})
@Arns
Copy link
Author

Arns commented Jun 2, 2022

Further digging in... I find toasted uses a container element nested under . When navigating using Vue turbolinks, the container element gets removed and never reinitialized. Turbolinks can keep elements permanent by adding an attribute - perhaps this would be a good workaround but I see no options for the container element when initializing toasted. Thoughts?

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

No branches or pull requests

1 participant