fix(turbo): patch turbo to make link_to work without global turbo enabled
This commit is contained in:
parent
ad25bd36bb
commit
219fc2f3bc
2 changed files with 41 additions and 5 deletions
|
@ -42,8 +42,12 @@
|
||||||
|
|
||||||
= yield :charts_js
|
= yield :charts_js
|
||||||
|
|
||||||
// Container for custom turbo-stream actions
|
// Container for custom turbo-stream actions
|
||||||
%turbo-events
|
%turbo-events
|
||||||
// Container for turbo form that we can submit from inside other forms
|
|
||||||
%div{ 'data-turbo': 'true' }
|
// We patch `@hotwired/turbo` to attach forms generated from links to this
|
||||||
= form_tag('', id: :turbo_form)
|
// container instead of the body to avoid conflicts with `@rails/ujs`. We also
|
||||||
|
// patch `@hotwired/turbo` to add a timeout before removing the form because in
|
||||||
|
// order to be accepted as a valid `turbo form`` either global `turbo drive`` should
|
||||||
|
// be enabled or the form needs to have a parent with `data-turbo="true"` on it.
|
||||||
|
%div{ 'data-turbo': 'true' }
|
||||||
|
|
32
patches/@hotwired+turbo+7.1.0.patch
Normal file
32
patches/@hotwired+turbo+7.1.0.patch
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
diff --git a/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js b/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js
|
||||||
|
index 963422f..65364f1 100644
|
||||||
|
--- a/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js
|
||||||
|
+++ b/node_modules/@hotwired/turbo/dist/turbo.es2017-esm.js
|
||||||
|
@@ -2621,9 +2621,9 @@ class Session {
|
||||||
|
form.addEventListener("turbo:submit-start", () => form.remove());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
- form.addEventListener("submit", () => form.remove());
|
||||||
|
+ form.addEventListener("submit", () => setTimeout(() => form.remove(), 500));
|
||||||
|
}
|
||||||
|
- document.body.appendChild(form);
|
||||||
|
+ (document.querySelector('body > [data-turbo="true"]') || document.body).appendChild(form);
|
||||||
|
return dispatch("submit", { cancelable: true, target: form });
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
diff --git a/node_modules/@hotwired/turbo/dist/turbo.es2017-umd.js b/node_modules/@hotwired/turbo/dist/turbo.es2017-umd.js
|
||||||
|
index 101db1f..ce43031 100644
|
||||||
|
--- a/node_modules/@hotwired/turbo/dist/turbo.es2017-umd.js
|
||||||
|
+++ b/node_modules/@hotwired/turbo/dist/turbo.es2017-umd.js
|
||||||
|
@@ -2627,9 +2627,9 @@ Copyright © 2021 Basecamp, LLC
|
||||||
|
form.addEventListener("turbo:submit-start", () => form.remove());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
- form.addEventListener("submit", () => form.remove());
|
||||||
|
+ form.addEventListener("submit", () => setTimeout(() => form.remove(), 500));
|
||||||
|
}
|
||||||
|
- document.body.appendChild(form);
|
||||||
|
+ (document.querySelector('body > [data-turbo="true"]') || document.body).appendChild(form);
|
||||||
|
return dispatch("submit", { cancelable: true, target: form });
|
||||||
|
}
|
||||||
|
else {
|
Loading…
Reference in a new issue