Turbolinks duplicate invoke
See original GitHub issueA simple test demo, it invoked multiple times connect
function when Turbolinks changed pages. Is it a bug?
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:
- Created 5 years ago
- Comments:6
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Maybe this is the final solution: https://github.com/turbolinks/turbolinks/pull/390
@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.