Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate from turbolinks to turbo drive #1834

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cmd/dcrdata/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/dcrdata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"webpack-merge": "^5.7.3"
},
"dependencies": {
"@hotwired/turbo": "^7.0.0-beta.5",
"bootstrap": "^4.6.0",
"dompurify": "^2.2.8",
"lodash-es": "^4.17.21",
Expand Down
2 changes: 1 addition & 1 deletion cmd/dcrdata/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const application = Application.start()
const context = require.context('./js/controllers', true, /\.js$/)
application.load(definitionsFromContext(context))

document.addEventListener('turbolinks:load', function (e) {
document.addEventListener('turbo:load', function (e) {
document.querySelectorAll('.jsonly').forEach((el) => {
el.classList.remove('jsonly')
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/dcrdata/public/js/controllers/address_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getDefault } from '../helpers/module_helper'
import { padPoints, sizedBarPlotter } from '../helpers/chart_helper'
import Zoom from '../helpers/zoom_helper'
import globalEventBus from '../services/event_bus_service'
import TurboQuery from '../helpers/turbolinks_helper'
import TurboQuery from '../helpers/turbodrive_helper'
import axios from 'axios'
import humanize from '../helpers/humanize_helper'
import txInBlock from '../helpers/block_helper'
Expand Down
2 changes: 1 addition & 1 deletion cmd/dcrdata/public/js/controllers/attackcost_controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Controller } from 'stimulus'
import TurboQuery from '../helpers/turbolinks_helper'
import TurboQuery from '../helpers/turbodrive_helper'
import { getDefault } from '../helpers/module_helper'
import globalEventBus from '../services/event_bus_service'
import dompurify from 'dompurify'
Expand Down
2 changes: 1 addition & 1 deletion cmd/dcrdata/public/js/controllers/charts_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { darkEnabled } from '../services/theme_service'
import { animationFrame } from '../helpers/animation_helper'
import { getDefault } from '../helpers/module_helper'
import axios from 'axios'
import TurboQuery from '../helpers/turbolinks_helper'
import TurboQuery from '../helpers/turbodrive_helper'
import globalEventBus from '../services/event_bus_service'
import { isEqual } from '../helpers/chart_helper'
import dompurify from 'dompurify'
Expand Down
2 changes: 1 addition & 1 deletion cmd/dcrdata/public/js/controllers/market_controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Controller } from 'stimulus'
import TurboQuery from '../helpers/turbolinks_helper'
import TurboQuery from '../helpers/turbodrive_helper'
import { getDefault } from '../helpers/module_helper'
import humanize from '../helpers/humanize_helper'
import { darkEnabled } from '../services/theme_service'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global Turbolinks */
import { Controller } from 'stimulus'
import Url from 'url-parse'
import * as Turbo from '@hotwired/turbo'

export default class extends Controller {
static get targets () {
Expand All @@ -18,15 +18,15 @@ export default class extends Controller {
q.byvotestatus = this.votestatusTarget.selectedOptions[0].value
}
url.set('query', q)
Turbolinks.visit(url.toString())
Turbo.visit(url.toString())
}

setFilterbyVoteStatus () {
const url = Url(window.location.href)
const q = {}
q.byvotestatus = this.votestatusTarget.selectedOptions[0].value
url.set('query', q)
Turbolinks.visit(url.toString())
Turbo.visit(url.toString())
}

setListView () {
Expand All @@ -36,6 +36,6 @@ export default class extends Controller {
url.set('query', {})
}
url.set('pathname', newPeriod)
Turbolinks.visit(url.href)
Turbo.visit(url.href)
}
}
4 changes: 2 additions & 2 deletions cmd/dcrdata/public/js/controllers/search_controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global Turbolinks */
import { Controller } from 'stimulus'
import * as Turbo from '@hotwired/turbo'

export default class extends Controller {
execute (e) {
Expand All @@ -8,6 +8,6 @@ export default class extends Controller {
if (search === '') {
return
}
Turbolinks.visit('/search?search=' + search)
Turbo.visit('/search?search=' + search)
}
}
6 changes: 3 additions & 3 deletions cmd/dcrdata/public/js/controllers/status_controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* global Turbolinks */
import { Controller } from 'stimulus'
import dompurify from 'dompurify'
import ws from '../services/messagesocket_service'
import Notify from 'notifyjs'
import globalEventBus from '../services/event_bus_service'
import * as Turbo from '@hotwired/turbo'

function buildProgressBar (data) {
const clean = dompurify.sanitize
Expand Down Expand Up @@ -91,7 +91,7 @@ export default class extends Controller {
if (!Notify.needsPermission) doNotification()

this.messageTarget.querySelector('h5').textContent = 'Blockchain sync is complete. Redirecting to home in 20 secs.'
setTimeout(() => Turbolinks.visit('/'), 20000)
setTimeout(() => Turbo.visit('/'), 20000)
return
}
}
Expand All @@ -107,7 +107,7 @@ export default class extends Controller {

_processBlock (blockData) {
if (this.hasFutureBlockTarget) {
Turbolinks.visit(window.location, { action: 'replace' })
Turbo.visit(window.location, { action: 'replace' })
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* global Turbolinks */
import Url from 'url-parse'
import * as Turbo from '@hotwired/turbo'

export default class TurboQuery {
constructor (turbolinks) {
constructor (turbo) {
const tq = this
tq.replaceTimer = 0
tq.appendTimer = 0
tq.turbolinks = turbolinks || Turbolinks || false
if (!tq.turbolinks || !tq.turbolinks.supported) {
console.error('No passed or global Turbolinks instance detected. TurboQuery requires Turbolinks.')
tq.turbo = turbo || Turbo || false
if (!tq.turbo) {
console.error('No passed or global Turbo instance detected. TurboQuery requires Turbo.')
return
}
// These are timer callbacks. Bind them to the TurboQuery instance.
Expand All @@ -33,16 +33,17 @@ export default class TurboQuery {

_replaceHistory () {
// see https://github.com/turbolinks/turbolinks/issues/219. This also works:
// window.history.replaceState(window.history.state, this.addr, this.url.href)
this.turbolinks.controller.replaceHistoryWithLocationAndRestorationIdentifier(this.turbolinks.Location.wrap(this.url.href), this.turbolinks.uuid())
window.history.replaceState(window.history.state, this.addr, this.url.href)
// this.turbo.controller.replaceHistoryWithLocationAndRestorationIdentifier(this.turbo.Location.wrap(this.url.href), this.turbo.uuid())
this.replaceTimer = 0
}

_appendHistory () {
// same as replaceHref, but creates a new entry in history for navigating
// with the browsers forward and back buttons. May still not work because of
// TurboLinks caching behavior, I think.
this.turbolinks.controller.pushHistoryWithLocationAndRestorationIdentifier(this.turbolinks.Location.wrap(this.url.href), this.turbolinks.uuid())
window.history.pushState(window.history.state, this.addr, this.url.href)
// this.turbo.controller.pushHistoryWithLocationAndRestorationIdentifier(this.turbo.Location.wrap(this.url.href), this.turbo.uuid())
this.appendTimer = 0
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/dcrdata/public/js/services/keyboard_navigation_service.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* global Turbolinks */
import { toggleMenu, toggleSun, closeMenu } from '../services/theme_service'
import { setCookie } from './cookie_service'
import Mousetrap from 'mousetrap'
import { addPauseToMousetrap } from '../vendor/mousetrap-pause'
import * as Turbo from '@hotwired/turbo'

addPauseToMousetrap(Mousetrap)

Expand Down Expand Up @@ -130,7 +130,7 @@ Mousetrap.bind('enter', function (e) {
jumpToIndexOnLoad = currentIndex
}
currentTarget.classList.add('activated')
Turbolinks.visit(location)
Turbo.visit(location)
}
})

Expand Down Expand Up @@ -169,7 +169,7 @@ if (keyNavEnabled()) {

keyNavToggle.querySelector('.text').textContent = keyNavEnabled() ? 'Disable Hot Keys' : 'Enable Hot Keys'

document.addEventListener('turbolinks:load', function (e) {
document.addEventListener('turbo:load', function (e) {
closeMenu(e)
if (keyNavEnabled()) {
keyNav(e, true)
Expand Down
2 changes: 1 addition & 1 deletion cmd/dcrdata/public/js/services/theme_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function toggleSun () {
}
}

document.addEventListener('turbolinks:before-render', function (event) {
document.addEventListener('turbo:before-render', function (event) {
if (darkEnabled()) {
toggleToDarkClasses(event.data.newBody)
} else {
Expand Down
1 change: 1 addition & 0 deletions cmd/dcrdata/public/scss/themes.scss
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ body.darkBG {
.nav-pills .nav-link.active {
background-color: #2dd8a3;
color: black;
cursor: pointer;
}

.dcrdata-logo {
Expand Down
4 changes: 2 additions & 2 deletions cmd/dcrdata/views/address.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
data-target="address.pageminus">
<a class="page-link"
href="{{.Path}}?n={{.Limit}}&start={{if gt (subtract .Offset .Limit) 0}}{{subtract .Offset .Limit}}{{else}}0{{end}}&txntype={{$txType}}"
data-turbolinks="false"
data-turbo="false"
data-target="address.paginator"
data-action="address#prevPage"
>Previous</a>
Expand All @@ -216,7 +216,7 @@
data-target="address.pageplus">
<a class="page-link"
href="{{.Path}}?n={{.Limit}}&start={{add .Offset .Limit}}&txntype={{$txType}}"
data-turbolinks="false"
data-turbo="false"
data-target="address.paginator"
data-action="address#nextPage"
>Next</a>
Expand Down
2 changes: 1 addition & 1 deletion cmd/dcrdata/views/block.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
{{- else }}
<a class="fs13" href="/mempool">mempool </a>|
{{- end}}
<a class="fs13" href="/api/block/{{.Height}}/verbose?indent=true" data-turbolinks="false">api</a>
<a class="fs13" href="/api/block/{{.Height}}/verbose?indent=true" data-turbo="false">api</a>
</div>
</div>
</div>
Expand Down
20 changes: 9 additions & 11 deletions cmd/dcrdata/views/extras.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{define "html-head"}}
<head data-turbolinks-eval="false">
<head data-turbo-eval="false">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
Expand Down Expand Up @@ -36,7 +36,7 @@
<meta name="msapplication-config" content="/images/favicon/browserconfig.xml?v=65tv3">
<!-- End custom favicon -->

<meta name="turbolinks-cache-control" content="no-cache">
<meta name="turbo-cache-control" content="no-cache">
<title>{{.}}</title>
<link rel="preload" href="/fonts/icomoon.ttf?g003m6" as="font" type="font/ttf" crossorigin="anonymous" />
<link rel="preload" href="/fonts/inconsolata-v15-latin-regular.woff?x=65tv3" as="font" type="font/woff" crossorigin="anonymous" />
Expand All @@ -47,8 +47,6 @@
<link rel="preload" href="/images/connected.svg?x=65tv3" as="image" type="image/svg+xml" />
<link rel="preload" href="/images/disconnected.svg?x=65tv3" as="image" type="image/svg+xml" />
<link href="/dist/css/style.css?v=uV0HsM7" rel="stylesheet">

<script src="/js/vendor/turbolinks.min.js?v=65tv3"></script>
</head>
{{end}}

Expand Down Expand Up @@ -77,7 +75,7 @@
/>
<button class="search-bttn" type="submit"><span class="dcricon-search"></span></button>
</form>
<nav id="hamburger-menu" data-controller="menu" data-turbolinks-permanent>
<nav id="hamburger-menu" data-controller="menu" data-turbo-permanent>
<div id="menuToggle">
<input type="checkbox" data-target="menu.toggle" data-action="change->menu#toggle"/>
<span class="patty"></span>
Expand Down Expand Up @@ -113,7 +111,7 @@
</div>
</button>
</form>
<a class="menu-item jsonly" data-keynav-skip data-turbolinks="false" href="#" id="keynav-toggle">
<a class="menu-item jsonly" data-keynav-skip data-turbo="false" href="#" id="keynav-toggle">
<span class="text">Enable Hot Keys</span><span class="keys-hint">(&nbsp;&nbsp;<span class="arrows"> &#8592;<br>&#8594;</span>&nbsp;&nbsp;enter&nbsp;&nbsp;\&nbsp;&nbsp;=&nbsp;&nbsp;)</span>
</a>
<a class="menu-item" data-keynav-skip href="{{.Links.APIDocs}}" title="API Endpoints" target="_blank" rel="noopener noreferrer">JSON API Docs</a>
Expand Down Expand Up @@ -157,7 +155,7 @@
<span
id="connection"
class="text-nowrap align-items-center clickable d-inline-block"
data-turbolinks-permanent
data-turbo-permanent
data-controller="connection"
data-target="connection.indicator"
data-action="click->connection#requestNotifyPermission"
Expand All @@ -167,13 +165,13 @@
</div>
<script
src="/dist/js/4.bundle.js?v=uV0HsM5"
data-turbolinks-eval="false"
data-turbolinks-suppress-warning
data-turbo-eval="false"
data-turbo-suppress-warning
></script>
<script
src="/dist/js/app.bundle.js?v=uV0HsM5"
data-turbolinks-eval="false"
data-turbolinks-suppress-warning
data-turbo-eval="false"
data-turbo-suppress-warning
></script>
</footer>
{{end}}
Expand Down
4 changes: 2 additions & 2 deletions cmd/dcrdata/views/treasury.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
data-target="address.pageminus">
<a class="page-link"
href="{{.Path}}?n={{.Limit}}&start={{if gt (subtract .Offset .Limit) 0}}{{subtract .Offset .Limit}}{{else}}0{{end}}&txntype={{$txType}}"
data-turbolinks="false"
data-turbo="false"
data-target="address.paginator"
data-action="address#prevPage"
>Previous</a>
Expand All @@ -172,7 +172,7 @@
data-target="address.pageplus">
<a class="page-link"
href="{{.Path}}?n={{.Limit}}&start={{add .Offset .Limit}}&txntype={{$txType}}"
data-turbolinks="false"
data-turbo="false"
data-target="address.paginator"
data-action="address#nextPage"
>Next</a>
Expand Down
6 changes: 3 additions & 3 deletions cmd/dcrdata/views/tx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@
>Raw Tx:
</td>
<td class="text-left py-1 text-secondary"><a
href="/api/tx/decoded/{{.TxID}}?indent=true" data-turbolinks="false">decoded</a> &middot; <a
href="/api/tx/hex/{{.TxID}}" data-turbolinks="false">hex</a>
href="/api/tx/decoded/{{.TxID}}?indent=true" data-turbo="false">decoded</a> &middot; <a
href="/api/tx/hex/{{.TxID}}" data-turbo="false">hex</a>
</td>
<td class="text-right medium-sans text-nowrap pr-2 py-2"
>Time:
Expand All @@ -254,7 +254,7 @@
>Swaps Info:
</td>
<td class="text-left py-1 text-secondary"><a
href="/api/tx/swaps/{{.TxID}}?indent=true" data-turbolinks="false">swaps</a>
href="/api/tx/swaps/{{.TxID}}?indent=true" data-turbo="false">swaps</a>
</td>
</tr>
{{end}}
Expand Down
3 changes: 0 additions & 3 deletions cmd/dcrdata/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ module.exports = {
entry: {
app: './public/index.js'
},
externals: {
turbolinks: 'Turbolinks'
},
optimization: {
chunkIds: 'natural',
splitChunks: {
Expand Down