Skip to content

Commit c433596

Browse files
committed
Disable Turbo for form submissions with custom packs
With Turbo enabled on forms with custom JavaScript / CSS packs and a successful change (no validation error), the final page would be rendered twice: The first rendering would occur after sending the form data using Turbo. This response is fetched and potentially displayed (first visit). The resulting DOM contains a change in the packs (with `'data-turbo-track': 'reload'`), causing a page reload (without Turbo). This is the second visit. Through this "double-visit", any flash message intended to be shown after the form submission is simply "lost". Therefore, we disable Turbo in these cases. This holds also true for signout actions, that can (potentially) originate from any page, including those with custom packs, and redirect to the root page (without any additional packs).
1 parent 7626432 commit c433596

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

app/views/application/_session.html.slim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
- if current_user.admin? || current_user.teacher? || current_user.internal_user?
1818
li = link_to(t('consumers.show.link'), current_user.consumer, class: 'dropdown-item') if current_user.consumer && policy(current_user.consumer).show?
1919
li = link_to(t('internal_users.show.link'), current_user, class: 'dropdown-item') if policy(current_user).show?
20-
li = button_to(t('sessions.destroy.link'), sign_out_path, method: :delete, class: 'dropdown-item')
20+
li = button_to(t('sessions.destroy.link'), sign_out_path, method: :delete, class: 'dropdown-item', data: {turbo: false})
2121
- elsif current_user.webauthn_configured?
22-
li = button_to(t('sessions.destroy.link'), sign_out_path, method: :delete, class: 'dropdown-item')
22+
li = button_to(t('sessions.destroy.link'), sign_out_path, method: :delete, class: 'dropdown-item', data: {turbo: false})
2323
- else
24-
li = button_to(t('sessions.destroy.link'), sign_out_path, method: :delete, class: 'dropdown-item')
24+
li = button_to(t('sessions.destroy.link'), sign_out_path, method: :delete, class: 'dropdown-item', data: {turbo: false})
2525
- else
2626
li.nav-item = link_to(sign_in_path, class: 'nav-link') do
2727
i.fa-solid.fa-arrow-right-to-bracket

app/views/execution_environments/_form.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- append_javascript_pack_tag('toast-ui')
66
- append_stylesheet_pack_tag('toast-ui')
77

8-
= form_for(@execution_environment, builder: MarkdownFormBuilder) do |f|
8+
= form_for(@execution_environment, builder: MarkdownFormBuilder, data: {turbo: false}) do |f|
99
= render('shared/form_errors', object: @execution_environment)
1010
.mb-3
1111
= f.label(:name, class: 'form-label')

app/views/exercises/_form.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- execution_environments = ExecutionEnvironment.where.not(file_type_id: nil).select(:file_type_id, :id)
1111
- file_types = FileType.where.not(file_extension: nil).select(:file_extension, :id)
1212

13-
= form_for(@exercise, data: {execution_environments:, file_types:}, multipart: true, builder: MarkdownFormBuilder) do |f|
13+
= form_for(@exercise, data: {execution_environments:, file_types:, turbo: false}, multipart: true, builder: MarkdownFormBuilder) do |f|
1414
= render('shared/form_errors', object: @exercise)
1515
.mb-3
1616
= f.label(:title, class: 'form-label')

app/views/exercises/index.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ h1 = Exercise.model_name.human(count: :other)
5252
li = link_to(RequestForComment.model_name.human(count: :other), exercise_request_for_comments_path(exercise), class: 'dropdown-item') if policy(exercise).rfcs_for_exercise?
5353
li = link_to(ProgrammingGroup.model_name.human(count: :other), exercise_programming_groups_path(exercise), class: 'dropdown-item') if policy(exercise).programming_groups_for_exercise?
5454
li = button_to(t('shared.destroy'), exercise, data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'dropdown-item') if policy(exercise).destroy?
55-
li = button_to(t('.clone'), clone_exercise_path(exercise), data: {confirm: t('shared.confirm_destroy')}, method: :post, class: 'dropdown-item') if policy(exercise).clone?
55+
li = button_to(t('.clone'), clone_exercise_path(exercise), data: {confirm: t('shared.confirm_destroy'), turbo: false}, method: :post, class: 'dropdown-item') if policy(exercise).clone?
5656
li = link_to(t('exercises.export_codeharbor.label'), '', class: 'dropdown-item export-start', data: {'exercise-id': exercise.id, 'bs-toggle': 'modal', 'bs-target': '#transfer-modal'}) if policy(exercise).export_external_confirm?
5757
li = link_to(t('exercises.download_proforma.label'), download_proforma_exercise_path(exercise), class: 'dropdown-item', target: '_blank', rel: 'noopener noreferrer') if policy(exercise).download_proforma?
5858

app/views/proxy_exercises/_form.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- append_javascript_pack_tag('toast-ui')
66
- append_stylesheet_pack_tag('toast-ui')
77

8-
= form_for(@proxy_exercise, multipart: true, builder: MarkdownFormBuilder) do |f|
8+
= form_for(@proxy_exercise, multipart: true, builder: MarkdownFormBuilder, data: {turbo: false}) do |f|
99
= render('shared/form_errors', object: @proxy_exercise)
1010
.mb-3
1111
= f.label(:title, class: 'form-label')

app/views/tips/_form.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- append_javascript_pack_tag('toast-ui')
77
- append_stylesheet_pack_tag('toast-ui')
88

9-
= form_for(@tip, builder: MarkdownFormBuilder) do |f|
9+
= form_for(@tip, builder: MarkdownFormBuilder, data: {turbo: false}) do |f|
1010
= render('shared/form_errors', object: @tip)
1111
.mb-3
1212
= f.label(:title, class: 'form-label')

app/views/webauthn_credential_authentication/_form.html.slim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
= hidden_field_tag('webauthn_credential[credential]', '')
44
.actions.mb-0
55
= submit_tag(t('.verify_identity'), class: 'btn btn-primary me-2 mb-2')
6-
= button_to(t('.cancel'), sign_out_path, method: :delete, class: 'btn btn-outline-secondary mb-2')
6+
= button_to(t('.cancel'), sign_out_path, method: :delete, class: 'btn btn-outline-secondary mb-2', data: {turbo: false})

0 commit comments

Comments
 (0)