Deprecar Turbolinks en favor de Turbo

Funciona mejor con navegación por anchors también
This commit is contained in:
f 2021-09-17 15:29:02 -03:00
parent 1ff252e328
commit 53f757e13e
3 changed files with 14 additions and 21 deletions

View file

@ -9,8 +9,14 @@ window.airbrake = new Notifier({
import 'core-js/stable' import 'core-js/stable'
import 'regenerator-runtime/runtime' import 'regenerator-runtime/runtime'
const Turbolinks = require("turbolinks") // Turbo acelera la navegación al no tener que recargar todo el JS y CSS
Turbolinks.start() // de la página, con lo que se siente más rápida y "nativa".
//
// Cambiamos de turbolinks a turbo porque turbo soporta la función
// fetch(), que luego es interceptada por el SW para obtener las
// direcciones localmente.
import * as Turbo from "@hotwired/turbo"
Turbo.start()
import { Application } from 'stimulus' import { Application } from 'stimulus'
import { definitionsFromContext } from "stimulus/webpack-helpers" import { definitionsFromContext } from "stimulus/webpack-helpers"
@ -19,23 +25,6 @@ const application = Application.start()
const context = require.context("./controllers", true, /\.js$/) const context = require.context("./controllers", true, /\.js$/)
application.load(definitionsFromContext(context)) application.load(definitionsFromContext(context))
// Prevenir que Turbolinks interfiera con la navegación por anchors
// https://github.com/turbolinks/turbolinks/issues/75#issuecomment-445325162
document.addEventListener('turbolinks:click', event => {
const anchorElement = event.target
const isSamePageAnchor = (
anchorElement.hash &&
anchorElement.origin === window.location.origin &&
anchorElement.pathname === window.location.pathname
)
if (!isSamePageAnchor) return
Turbolinks.controller.pushHistoryWithLocationAndRestorationIdentifier(event.data.url, Turbolinks.uuid())
event.preventDefault()
})
try { try {
window.axe = require('axe-core/axe') window.axe = require('axe-core/axe')
} catch(e) {} } catch(e) {}
@ -45,8 +34,6 @@ if (window.axe) window.axe.configure({ locale: require('axe-core/locales/es.json
// Prevenir que Turbolinks interfiera la navegación a un anchor al // Prevenir que Turbolinks interfiera la navegación a un anchor al
// recargar la página // recargar la página
document.addEventListener('turbolinks:load', event => { document.addEventListener('turbolinks:load', event => {
window.location.hash = window.location.hash
if (!window.axe) return if (!window.axe) return
window.axe.run().then(results => { window.axe.run().then(results => {

View file

@ -12,6 +12,7 @@
"@babel/core": "^7.10.4", "@babel/core": "^7.10.4",
"@babel/plugin-proposal-class-properties": "^7.10.4", "@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/preset-env": "^7.10.4", "@babel/preset-env": "^7.10.4",
"@hotwired/turbo": "^7.0.0-rc.4",
"axe-core": "^4.1.2", "axe-core": "^4.1.2",
"babel-loader": "^8.1.0", "babel-loader": "^8.1.0",
"core-js": "^3.6.5", "core-js": "^3.6.5",

View file

@ -880,6 +880,11 @@
"@babel/helper-validator-identifier" "^7.14.0" "@babel/helper-validator-identifier" "^7.14.0"
to-fast-properties "^2.0.0" to-fast-properties "^2.0.0"
"@hotwired/turbo@^7.0.0-rc.4":
version "7.0.0-rc.4"
resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-7.0.0-rc.4.tgz#d3ab9555544534f5ec649613553e72ff6c7d7122"
integrity sha512-4qx+6O6mUN+cSN+ZLGCOGc+2MxNrs7cFbmnWD6LIfiHAQyuNiIuB87Y5IAtOo8xj16fOBd2CdU1WRJya4Wkw0A==
"@sindresorhus/is@^0.14.0": "@sindresorhus/is@^0.14.0":
version "0.14.0" version "0.14.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea" resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea"