From b5f1d9762953c40ed4613d6aee8d0ae7922c866f Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 7 May 2020 14:31:36 +0000 Subject: [PATCH] app: disable Turbolinks Fix #5039 --- Gemfile | 1 - Gemfile.lock | 4 ---- .../old_design/bootstrap_wysihtml5.js | 2 +- .../old_design/default_data_block.js | 2 +- .../old_design/dossiers_list_filter.js | 2 +- .../javascripts/old_design/input_helpers.js | 2 +- .../old_design/instructeur_dossier_modal.js | 2 +- .../javascripts/old_design/procedure.js | 2 +- app/assets/stylesheets/_turbolinks.scss | 5 ----- app/assets/stylesheets/application.scss | 1 - app/javascript/new_design/champs/carte.js | 2 +- app/javascript/packs/application-old.js | 2 -- app/javascript/packs/application.js | 4 ---- app/javascript/shared/page-update-event.js | 2 +- app/javascript/shared/remote-poller.js | 2 +- app/javascript/shared/track/matomo.js | 19 ------------------- .../procedures/new_from_existing.html.haml | 2 +- .../procedures/deleted_dossiers.html.haml | 2 +- .../instructeurs/procedures/show.html.haml | 2 +- app/views/layouts/_footer.html.haml | 2 +- app/views/layouts/application.html.haml | 7 +++---- app/views/layouts/application_old.html.haml | 9 ++++----- app/views/root/_footer.html.haml | 2 +- package.json | 1 - spec/features/routing/full_scenario_spec.rb | 2 +- yarn.lock | 5 ----- 26 files changed, 22 insertions(+), 66 deletions(-) delete mode 100644 app/assets/stylesheets/_turbolinks.scss diff --git a/Gemfile b/Gemfile index a25e31a69..d04fdc976 100644 --- a/Gemfile +++ b/Gemfile @@ -71,7 +71,6 @@ gem 'skylight' gem 'smart_listing' gem 'spreadsheet_architect' gem 'sprockets', '< 4' -gem 'turbolinks' # Turbolinks makes following links in your web application faster gem 'typhoeus' gem 'warden' gem 'webpacker' diff --git a/Gemfile.lock b/Gemfile.lock index 3723c4b8c..3f1773f27 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -663,9 +663,6 @@ GEM tilt (2.0.10) timecop (0.9.1) ttfunk (1.5.1) - turbolinks (5.2.0) - turbolinks-source (~> 5.2) - turbolinks-source (5.2.0) typhoeus (1.3.1) ethon (>= 0.9.0) tzinfo (1.2.7) @@ -823,7 +820,6 @@ DEPENDENCIES spring-commands-rspec sprockets (< 4) timecop - turbolinks typhoeus vcr warden diff --git a/app/assets/javascripts/old_design/bootstrap_wysihtml5.js b/app/assets/javascripts/old_design/bootstrap_wysihtml5.js index 0c5a76d3f..9d9e0d864 100644 --- a/app/assets/javascripts/old_design/bootstrap_wysihtml5.js +++ b/app/assets/javascripts/old_design/bootstrap_wysihtml5.js @@ -1,6 +1,6 @@ /* globals $ */ -$(document).on('turbolinks:load', wysihtml5_active); +$(document).on('DOMContentLoaded', wysihtml5_active); function wysihtml5_active() { $('.wysihtml5').each(function (i, elem) { diff --git a/app/assets/javascripts/old_design/default_data_block.js b/app/assets/javascripts/old_design/default_data_block.js index 07cc43512..6f682fd91 100644 --- a/app/assets/javascripts/old_design/default_data_block.js +++ b/app/assets/javascripts/old_design/default_data_block.js @@ -1,6 +1,6 @@ /* globals $ */ -$(document).on('turbolinks:load', init_default_data_block); +$(document).on('DOMContentLoaded', init_default_data_block); function init_default_data_block() { $('.default-data-block #dossier .body').toggle(); diff --git a/app/assets/javascripts/old_design/dossiers_list_filter.js b/app/assets/javascripts/old_design/dossiers_list_filter.js index ac19c85bd..15e344199 100644 --- a/app/assets/javascripts/old_design/dossiers_list_filter.js +++ b/app/assets/javascripts/old_design/dossiers_list_filter.js @@ -1,6 +1,6 @@ /* globals $ */ -$(document).on('turbolinks:load', filters_init); +$(document).on('DOMContentLoaded', filters_init); function filters_init() { $('html').click(function (event) { diff --git a/app/assets/javascripts/old_design/input_helpers.js b/app/assets/javascripts/old_design/input_helpers.js index d4b60cbc7..6a8aeb8d6 100644 --- a/app/assets/javascripts/old_design/input_helpers.js +++ b/app/assets/javascripts/old_design/input_helpers.js @@ -1,6 +1,6 @@ /* globals $ */ -$(document).on('turbolinks:load', action_type_de_champs); +$(document).on('DOMContentLoaded', action_type_de_champs); function action_type_de_champs() { $("input[type='email']").on('change', function () { diff --git a/app/assets/javascripts/old_design/instructeur_dossier_modal.js b/app/assets/javascripts/old_design/instructeur_dossier_modal.js index da943bb99..40ea0b5c9 100644 --- a/app/assets/javascripts/old_design/instructeur_dossier_modal.js +++ b/app/assets/javascripts/old_design/instructeur_dossier_modal.js @@ -1,6 +1,6 @@ /* globals $ */ -$(document).on('turbolinks:load', modal_action); +$(document).on('DOMContentLoaded', modal_action); function modal_action() { $('#pj-modal').on('show.bs.modal', function (event) { diff --git a/app/assets/javascripts/old_design/procedure.js b/app/assets/javascripts/old_design/procedure.js index e029875ef..007b6b40c 100644 --- a/app/assets/javascripts/old_design/procedure.js +++ b/app/assets/javascripts/old_design/procedure.js @@ -1,6 +1,6 @@ /* globals $ */ -$(document).on('turbolinks:load', button_edit_procedure_init); +$(document).on('DOMContentLoaded', button_edit_procedure_init); function button_edit_procedure_init() { buttons_api_carto(); diff --git a/app/assets/stylesheets/_turbolinks.scss b/app/assets/stylesheets/_turbolinks.scss deleted file mode 100644 index 436f0541c..000000000 --- a/app/assets/stylesheets/_turbolinks.scss +++ /dev/null @@ -1,5 +0,0 @@ -@import "constants"; - -.turbolinks-progress-bar { - background-color: $light-blue; -} diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index ee4b980da..d4990fbba 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -11,7 +11,6 @@ // // = require _card // = require _helpers -// = require _turbolinks // = require admin_type_de_champ // = require carte // = require custom_mails diff --git a/app/javascript/new_design/champs/carte.js b/app/javascript/new_design/champs/carte.js index a5b6c2ebe..8bf23eee4 100644 --- a/app/javascript/new_design/champs/carte.js +++ b/app/javascript/new_design/champs/carte.js @@ -25,7 +25,7 @@ async function loadAndRedrawMap(element, data) { redrawMap(element, data); } -addEventListener('turbolinks:load', initialize); +addEventListener('DOMContentLoaded', initialize); addEventListener('carte:update', ({ detail: { selector, data } }) => { const element = document.querySelector(selector); diff --git a/app/javascript/packs/application-old.js b/app/javascript/packs/application-old.js index a10e991fb..5f831fc68 100644 --- a/app/javascript/packs/application-old.js +++ b/app/javascript/packs/application-old.js @@ -1,5 +1,4 @@ import '../shared/polyfills'; -import Turbolinks from 'turbolinks'; import Rails from '@rails/ujs'; import * as ActiveStorage from '@rails/activestorage'; import jQuery from 'jquery'; @@ -13,7 +12,6 @@ import '../shared/franceconnect'; // Start Rails helpers Rails.start(); -Turbolinks.start(); ActiveStorage.start(); // Disable jQuery-driven animations during tests diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index b436909dd..b76cf557f 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -1,5 +1,4 @@ import '../shared/polyfills'; -import Turbolinks from 'turbolinks'; import Rails from '@rails/ujs'; import * as ActiveStorage from '@rails/activestorage'; import '@rails/actiontext'; @@ -57,13 +56,10 @@ const DS = { // Start Rails helpers Rails.start(); -Turbolinks.start(); ActiveStorage.start(); // Expose globals window.DS = window.DS || DS; -// (Both Rails redirects and ReactRailsUJS expect Turbolinks to be globally available) -window.Turbolinks = Turbolinks; // Now that Turbolinks is globally exposed,configure ReactRailsUJS // eslint-disable-next-line no-undef diff --git a/app/javascript/shared/page-update-event.js b/app/javascript/shared/page-update-event.js index 3f2cac2fb..7a2c2ace2 100644 --- a/app/javascript/shared/page-update-event.js +++ b/app/javascript/shared/page-update-event.js @@ -1,6 +1,6 @@ import { fire } from '@utils'; -addEventListener('turbolinks:load', function () { +addEventListener('DOMContentLoaded', function () { fire(document, 'ds:page:update'); }); diff --git a/app/javascript/shared/remote-poller.js b/app/javascript/shared/remote-poller.js index 84cf3a8ca..f4faa6c02 100644 --- a/app/javascript/shared/remote-poller.js +++ b/app/javascript/shared/remote-poller.js @@ -1,6 +1,6 @@ import { ajax, delegate } from '@utils'; -addEventListener('turbolinks:load', () => { +addEventListener('DOMContentLoaded', () => { attachementPoller.deactivate(); exportPoller.deactivate(); diff --git a/app/javascript/shared/track/matomo.js b/app/javascript/shared/track/matomo.js index 12db6b112..2e1512e58 100644 --- a/app/javascript/shared/track/matomo.js +++ b/app/javascript/shared/track/matomo.js @@ -25,23 +25,4 @@ if (enabled) { script.async = true; script.src = jsUrl; firstScript.parentNode.insertBefore(script, firstScript); - - // Send Matomo a new event when navigating to a new page using Turbolinks - // (see https://developer.matomo.org/guides/spa-tracking) - let previousPageUrl = null; - addEventListener('turbolinks:load', (event) => { - if (previousPageUrl) { - window._paq.push(['setReferrerUrl', previousPageUrl]); - window._paq.push(['setCustomUrl', window.location.href]); - window._paq.push(['setDocumentTitle', document.title]); - if (event.data && event.data.timing) { - window._paq.push([ - 'setGenerationTimeMs', - event.data.timing.visitEnd - event.data.timing.visitStart - ]); - } - window._paq.push(['trackPageView']); - } - previousPageUrl = window.location.href; - }); } diff --git a/app/views/admin/procedures/new_from_existing.html.haml b/app/views/admin/procedures/new_from_existing.html.haml index e171bd860..29bdda94c 100644 --- a/app/views/admin/procedures/new_from_existing.html.haml +++ b/app/views/admin/procedures/new_from_existing.html.haml @@ -27,7 +27,7 @@ target: "_blank" :javascript - document.addEventListener("turbolinks:load", function() { + document.addEventListener("DOMContentLoaded", function() { $crisp.push(["do", "trigger:run", ["admin-signup"]]); }); diff --git a/app/views/instructeurs/procedures/deleted_dossiers.html.haml b/app/views/instructeurs/procedures/deleted_dossiers.html.haml index bca8319cc..9063e18e2 100644 --- a/app/views/instructeurs/procedures/deleted_dossiers.html.haml +++ b/app/views/instructeurs/procedures/deleted_dossiers.html.haml @@ -11,7 +11,7 @@ %h1= procedure_libelle @procedure = link_to 'gestion des notifications', email_notifications_instructeur_procedure_path(@procedure), class: 'header-link' | - = link_to 'statistiques', stats_instructeur_procedure_path(@procedure), class: 'header-link', data: { turbolinks: false } # Turbolinks disabled for Chartkick. See Issue #350 + = link_to 'statistiques', stats_instructeur_procedure_path(@procedure), class: 'header-link' - if @procedure.routee? | diff --git a/app/views/instructeurs/procedures/show.html.haml b/app/views/instructeurs/procedures/show.html.haml index 9e4c01cbc..ac4b7f730 100644 --- a/app/views/instructeurs/procedures/show.html.haml +++ b/app/views/instructeurs/procedures/show.html.haml @@ -11,7 +11,7 @@ %h1= procedure_libelle @procedure = link_to 'gestion des notifications', email_notifications_instructeur_procedure_path(@procedure), class: 'header-link' | - = link_to 'statistiques', stats_instructeur_procedure_path(@procedure), class: 'header-link', data: { turbolinks: false } # Turbolinks disabled for Chartkick. See Issue #350 + = link_to 'statistiques', stats_instructeur_procedure_path(@procedure), class: 'header-link' - if @procedure.routee? | diff --git a/app/views/layouts/_footer.html.haml b/app/views/layouts/_footer.html.haml index 98d27f0ec..987bdd0f1 100644 --- a/app/views/layouts/_footer.html.haml +++ b/app/views/layouts/_footer.html.haml @@ -5,7 +5,7 @@ \- = link_to 'Nouveautés', 'https://doc.demarches-simplifiees.fr/nouveautes', target: '_blank' \- - = link_to 'Statistiques', stats_path, data: { turbolinks: false } # Turbolinks disabled for Chartkick. See Issue #350 + = link_to 'Statistiques', stats_path \- = link_to 'CGU / Mentions légales', CGU_URL, target: '_blank' \- diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index b915c3568..055c4eed0 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -3,7 +3,6 @@ %head %meta{ "http-equiv": "Content-Type", content: "text/html; charset=UTF-8" } %meta{ "http-equiv": "X-UA-Compatible", content: "IE=edge" } - %meta{ name: "turbolinks-cache-control", content: "no-cache" } %meta{ name: "viewport", content: "width=device-width, initial-scale=1" } = csrf_meta_tags @@ -15,9 +14,9 @@ = favicon_link_tag(image_url("favicons/96x96.png"), type: "image/png", sizes: "96x96") - packs = ['application', 'track', administrateur_signed_in? ? 'track-admin' : nil].compact - = javascript_packs_with_chunks_tag *packs, defer: true, 'data-turbolinks-track': 'reload' - = stylesheet_link_tag 'new_design/new_application', media: 'all', 'data-turbolinks-track': 'reload' - = stylesheet_link_tag 'new_design/print', media: 'print', 'data-turbolinks-track': 'reload' + = javascript_packs_with_chunks_tag *packs, defer: true + = stylesheet_link_tag 'new_design/new_application', media: 'all' + = stylesheet_link_tag 'new_design/print', media: 'print' = Gon::Base.render_data(camel_case: true, init: true, nonce: request.content_security_policy_nonce) diff --git a/app/views/layouts/application_old.html.haml b/app/views/layouts/application_old.html.haml index 96217b370..1857a849d 100644 --- a/app/views/layouts/application_old.html.haml +++ b/app/views/layouts/application_old.html.haml @@ -1,7 +1,6 @@ %html %head %meta{ :content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type" }/ - %meta{ name: "turbolinks-cache-control", content: "no-cache" } %title = t('dynamics.page_title') %meta{ 'http-equiv' => "X-UA-Compatible", :content => "IE=edge" } @@ -10,11 +9,11 @@ = favicon_link_tag(image_url("favicons/32x32.png"), type: "image/png", sizes: "32x32") = favicon_link_tag(image_url("favicons/96x96.png"), type: "image/png", sizes: "96x96") - = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': "reload" - = stylesheet_link_tag 'print', media: 'print', 'data-turbolinks-track': "reload" + = stylesheet_link_tag 'application', media: 'all' + = stylesheet_link_tag 'print', media: 'print' - packs = ['application-old', 'track', administrateur_signed_in? ? 'track-admin' : nil].compact - = javascript_packs_with_chunks_tag *packs, defer: true, 'data-turbolinks-track': 'reload' - = javascript_include_tag 'application', defer: true, 'data-turbolinks-track': 'reload' + = javascript_packs_with_chunks_tag *packs, defer: true + = javascript_include_tag 'application', defer: true = csrf_meta_tags = Gon::Base.render_data(camel_case: true, init: true) diff --git a/app/views/root/_footer.html.haml b/app/views/root/_footer.html.haml index a53e41c66..038e565a6 100644 --- a/app/views/root/_footer.html.haml +++ b/app/views/root/_footer.html.haml @@ -23,7 +23,7 @@ %li.footer-link = link_to "Nouveautés", "https://github.com/betagouv/demarches-simplifiees.fr/releases", :class => "footer-link", :title => "Nos nouveautés" %li.footer-link - = link_to "Statistiques", stats_path, :class => "footer-link", data: { turbolinks: false } # Turbolinks disabled for Chartkick. See Issue #350 + = link_to "Statistiques", stats_path, :class => "footer-link" %li.footer-link = link_to "CGU", CGU_URL, :class => "footer-link", :target => "_blank", rel: "noopener noreferrer" %li.footer-link diff --git a/package.json b/package.json index 63ff144da..266567478 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "react_ujs": "^2.6.1", "select2": "^4.0.13", "trix": "^1.2.3", - "turbolinks": "^5.2.0", "whatwg-fetch": "^3.0.0" }, "devDependencies": { diff --git a/spec/features/routing/full_scenario_spec.rb b/spec/features/routing/full_scenario_spec.rb index 612f38cd4..ef1c1c046 100644 --- a/spec/features/routing/full_scenario_spec.rb +++ b/spec/features/routing/full_scenario_spec.rb @@ -133,7 +133,7 @@ feature 'The routing', js: true do click_on 'suivi' click_on litteraire_user.email expect(page).to have_current_path(instructeur_dossier_path(procedure, litteraire_user.dossiers.first)) - expect(page).to have_text('Annotations privées') # ensure Turbolinks DID load the DOM content + expect(page).to have_text('Annotations privées') expect(find('.tabs')).to have_css('span.notifications') log_out diff --git a/yarn.lock b/yarn.lock index 40ceb76a8..ccb794fd6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9397,11 +9397,6 @@ tunnel-agent@^0.6.0: dependencies: safe-buffer "^5.0.1" -turbolinks@^5.2.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/turbolinks/-/turbolinks-5.2.0.tgz#e6877a55ea5c1cb3bb225f0a4ae303d6d32ff77c" - integrity sha512-pMiez3tyBo6uRHFNNZoYMmrES/IaGgMhQQM+VFF36keryjb5ms0XkVpmKHkfW/4Vy96qiGW3K9bz0tF5sK9bBw== - turf-intersect@~3.0.12: version "3.0.12" resolved "https://registry.yarnpkg.com/turf-intersect/-/turf-intersect-3.0.12.tgz#c0d7fb305843a19275670057a39d268b17830d83"