question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Turbolinks duplicate invoke

See original GitHub issue

A simple test demo, it invoked multiple times connect function when Turbolinks changed pages. Is it a bug?

stimulus-turoblinks

layout:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <script src="stimulus.js"></script>
  <script src="turblinks.js"></script>
  <script src="start.js"></script>
<head>
<body>

</body>
</html>

a.html

<div data-controller="hello">
  Page A
</div>
<a href="b.html">B</a>

b.html

<div data-controller="hello">
  Page B
</div>
<a href="a.html">A</a>

start.js

(() => {
  const application = Stimulus.Application.start()

  let count = 0
  application.register("hello", class extends Stimulus.Controller {
    connect() {
      console.log('controller connected', count++)
    }
  })
})()

Turbolinks.start()

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
bevizcommented, May 29, 2018

Maybe this is the final solution: https://github.com/turbolinks/turbolinks/pull/390

0reactions
bevizcommented, May 29, 2018

@skyksandr looks like add an data-action turbolinks:before-cache listener is more clearly, but every page which using this controller need to write it again, not worth.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Turbolinks duplicate invoke #160 - hotwired/stimulus - GitHub
A simple test demo, it invoked multiple times connect function when Turbolinks changed pages. Is it a bug? layout:
Read more >
How can I prevent duplicate wrappers on a jQuery DataTable ...
The only thing I've found that will prevent this wrapper duplication from happening is to simply remove the call to include the turbolinks...
Read more >
Turbolinks, browser back and duplicate plugins
Turbolinks saves a copy of the current page to its cache just before rendering a new page. Note that Turbolinks copies the page...
Read more >
Rails, turbolinks and javascript. How to avoid duplicate ...
You can filter out existing elements that have already been called by looking for data-switchery="true". var elem = document.querySelector('.js-switch:not([data ...
Read more >
Turbolinks Cheatsheet - Key Shift in Cmd
Copies the page to cache using cloneNode(true), so when it's returned from the cache, attached event listeners and associated data are discarded ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found