Skip to content

Commit b46b23c

Browse files
committed
Used teardown instead of disconnect to address reinitialization issues
1 parent dabaa6a commit b46b23c

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

app/assets/builds/administrate/application.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21377,6 +21377,13 @@
2137721377
var application = Application.start();
2137821378
application.debug = false;
2137921379
window.Stimulus = application;
21380+
document.addEventListener("turbo:before-cache", function() {
21381+
application.controllers.forEach(function(controller) {
21382+
if (typeof controller.teardown === "function") {
21383+
controller.teardown();
21384+
}
21385+
});
21386+
});
2138021387

2138121388
// app/assets/javascripts/administrate/controllers/select_controller.js
2138221389
var import_jquery2 = __toESM(require_jquery());
@@ -21389,7 +21396,7 @@
2138921396
this.selectize.setValue(selectedValues);
2139021397
}
2139121398
}
21392-
disconnect() {
21399+
teardown() {
2139321400
if (this.selectize) {
2139421401
const selectedValues = this.selectize.getValue();
2139521402
if (!this.selectizeOptions) {

app/assets/builds/administrate/application.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/assets/javascripts/administrate/controllers/application.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,14 @@ const application = Application.start();
66
application.debug = false;
77
window.Stimulus = application;
88

9+
// Workaround for Stimulus controllers not being properly disconnected
10+
// https://github.com/hotwired/stimulus/issues/104#issuecomment-365393601
11+
document.addEventListener('turbo:before-cache', function() {
12+
application.controllers.forEach(function(controller){
13+
if(typeof controller.teardown === 'function') {
14+
controller.teardown();
15+
}
16+
});
17+
});
18+
919
export { application };

app/assets/javascripts/administrate/controllers/select_controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default class extends Controller {
1111
}
1212
}
1313

14-
disconnect() {
14+
teardown() {
1515
if (this.selectize) {
1616
const selectedValues = this.selectize.getValue();
1717
if (!this.selectizeOptions) {

0 commit comments

Comments
 (0)