In a non-ruby environment, the Turbo documentation suggests a complete import of Turbo. After the import, the whole Turbo framework is active on the page.
I didn’t really realize that first as I only wanted to use turboframes. It activated Turbo Drive on the whole website, which I didn’t want to use. So, I wonder, is there no other way to initialize individual features of the Turbo framework part? Like only activate or import the turboframes part?
2 Likes
There’s now a way to deactivate Turbo Drive by default since rc.2 of Turbo.
hotwired:main
← gregschmit:gns/option-disable-drive-default
opened 02:24AM - 04 Mar 21 UTC
I have a project where customers have existing layouts and I don't want them to … have to disable Turbo Drive using `data-turbo="false"` in their layouts, but I still want them to be able to use Turbo in an opt-in fashion. Right now I monkey patch it like this, which seems hacky:
```js
import { Turbo } from "@hotwired/turbo-rails";
Turbo.navigator.delegate.elementIsNavigable = function(element) {
const container = element === null || element === void 0 ? void 0 : element.closest("[data-turbo]");
if (container) {
return container.getAttribute("data-turbo") == "true";
} else {
return false;
}
}
```
Turbo Drive seems to be the only part of Turbo which is not opt-in, so it seems wrong to not be able to configure it to behave that way. This PR would allow developers to disable Turbo Drive by default, and then opt-in by adding `data-turbo="true"` wherever they want to use Turbo Drive (including in the `<html>` or `<body>` tags). Usage after it's in `turbo-rails`:
```js
import { Turbo } from "@hotwired/turbo-rails";
Turbo.disableDriveByDefault();
```
The name might seem a little verbose, but I thought it was good because it communicates that it's not entirely disabled, and still usable in an opt-in fashion.
Fixes #190
Related to #136
Fixes hotwired/turbo-rails#139