From b594b5360c757adc9d9162d5395d433c1816f7ae Mon Sep 17 00:00:00 2001 From: Rob Cole Date: Mon, 7 Mar 2022 16:23:22 -0800 Subject: [PATCH] Add them links back (#948) * Revert "Replacing turbolinks with turbo. This fixes the issue with the search randomly disappearing. Fixes #917 (#932)" This reverts commit bb320a8ab97faf597a17029c1649c6a6e56b5193. # Conflicts: # package.json * Ensure docsearch is loaded on every turbo pageload This seems to resolve the issue around the searchbox not being visible in some situations. * Switch watcher port to 3000 by default Use of port 5000 has been deprecated in upstream CLI builds due to its conflicts on OSX. This allows for local dev in Mac-based environments more easily. --- config/watch.yml | 2 +- package.json | 6 +++--- src/components/shared/layout_head.cr | 4 ++-- src/js/app.js | 17 +++++++++++------ yarn.lock | 20 ++++++++++---------- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/config/watch.yml b/config/watch.yml index f4df5fe1..ea19b869 100644 --- a/config/watch.yml +++ b/config/watch.yml @@ -1,2 +1,2 @@ host: 127.0.0.1 -port: 5000 +port: 3000 diff --git a/package.json b/package.json index fe8d25e9..2077017e 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,10 @@ "private": true, "dependencies": { "@docsearch/js": "^3.0.0", - "@hotwired/turbo": "^7.1.0", - "@rails/ujs": "^7.0.2-2", "highlight.js": "^11.4.0", - "modern-normalize": "^1.1.0" + "modern-normalize": "^1.1.0", + "rails-ujs": "^5.2.6", + "turbolinks": "^5.2.0" }, "scripts": { "heroku-postbuild": "yarn prod", diff --git a/src/components/shared/layout_head.cr b/src/components/shared/layout_head.cr index 2a5812a2..ba0e90d6 100644 --- a/src/components/shared/layout_head.cr +++ b/src/components/shared/layout_head.cr @@ -5,8 +5,8 @@ class Shared::LayoutHead < BaseComponent head do utf8_charset title "Lucky - #{@seo.page_title}" - css_link asset("css/app.css"), data_turbo_track: "reload" - js_link asset("js/app.js"), defer: "defer", data_turbo_track: "reload" + css_link asset("css/app.css"), data_turbolinks_track: "reload" + js_link asset("js/app.js"), defer: "defer", data_turbolinks_track: "reload" csrf_meta_tags meta name: "description", content: @seo.page_description rss_link diff --git a/src/js/app.js b/src/js/app.js index f3eb54d3..f513a537 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -1,9 +1,13 @@ /* eslint no-console:0 */ // RailsUjs is *required* for links in Lucky that use DELETE, POST and PUT. -require("@rails/ujs").start(); -require("@hotwired/turbo"); +import RailsUjs from "rails-ujs"; +// Turbolinks is optional. Learn more: https://github.com/turbolinks/turbolinks/ +import Turbolinks from "turbolinks"; + +RailsUjs.start(); +Turbolinks.start(); import hljs from 'highlight.js/lib/core'; @@ -39,10 +43,7 @@ hljs.registerLanguage('diff', diff); import docsearch from '@docsearch/js'; -document.addEventListener("turbo:load", function () { - document.querySelectorAll('pre code').forEach((block) => { - hljs.highlightElement(block); - }); +document.addEventListener("turbolinks:load", function () { docsearch({ container: '#docsearch', @@ -50,4 +51,8 @@ document.addEventListener("turbo:load", function () { indexName: 'luckyframework', apiKey: '5d744498cfdcf4d4340dc3751c5bfd5f', }); + + document.querySelectorAll('pre code').forEach((block) => { + hljs.highlightElement(block); + }); }); diff --git a/yarn.lock b/yarn.lock index 8c9073a9..e8d53b08 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1058,11 +1058,6 @@ "@docsearch/css" "3.0.0" algoliasearch "^4.0.0" -"@hotwired/turbo@^7.1.0": - version "7.1.0" - resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-7.1.0.tgz#27e44e0e3dc5bd1d4bda0766d579cf5a14091cd7" - integrity sha512-Q8kGjqwPqER+CtpQudbH+3Zgs2X4zb6pBAlr6NsKTXadg45pAOvxI9i4QpuHbwSzR2+x87HUm+rot9F/Pe8rxA== - "@jridgewell/resolve-uri@^3.0.3": version "3.0.5" resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.0.5.tgz#68eb521368db76d040a6315cdb24bf2483037b9c" @@ -1102,11 +1097,6 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" -"@rails/ujs@^7.0.2-2": - version "7.0.2-2" - resolved "https://registry.yarnpkg.com/@rails/ujs/-/ujs-7.0.2-2.tgz#9f2f114f4777627034be541151a1240ebe585199" - integrity sha512-2M+stexFdUwVXMo4sborFkGEI7A7qEl8iIZX9oqW/JOjEyl6jpjpKAtPCAvKrXQAduX8lBQKHj/eTQKqONVB0Q== - "@trysound/sax@0.2.0": version "0.2.0" resolved "https://registry.yarnpkg.com/@trysound/sax/-/sax-0.2.0.tgz#cccaab758af56761eb7bf37af6f03f326dd798ad" @@ -4958,6 +4948,11 @@ quick-lru@^5.1.1: resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-5.1.1.tgz#366493e6b3e42a3a6885e2e99d18f80fb7a8c932" integrity sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA== +rails-ujs@^5.2.6: + version "5.2.6" + resolved "https://registry.yarnpkg.com/rails-ujs/-/rails-ujs-5.2.6.tgz#4193242a108d0cd9ed3595695644755c0bd329eb" + integrity sha512-JpUq5RlA4p5XE69dz0ZOIkn1xXQn9H8VDXQJWuVPRtFBOFylWFriaDVpxFmdQuARPo4bm2l67uIMMBpX6KNY+g== + randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5, randombytes@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.1.0.tgz#df6f84372f0270dc65cdf6291349ab7a473d4f2a" @@ -5828,6 +5823,11 @@ tty-browserify@0.0.0: resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6" integrity sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY= +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== + type-is@~1.6.18: version "1.6.18" resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131"