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

Add notes about ignored paths (related to hotwired/turbo#1070) #152

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
50 changes: 50 additions & 0 deletions _source/handbook/02_drive.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,54 @@ Preload links into Turbo Drive's cache using `<a href="/" data-turbo-preload>Hom
This will make page transitions feel lightning fast by providing a preview of a page even before the first visit. Use it to preload the most important pages in your application. Avoid over usage, as it will lead to loading content that is not needed.

It also dovetails nicely with pages that leverage [Eager-Loading Frames](/reference/frames#eager-loaded-frame) or [Lazy-Loading Frames](/reference/frames#lazy-loaded-frame). As you can preload the structure of the page and show the user a meaningful loading state while the interesting content loads.

## Ignored Paths

Paths with a `.` in the last level of a path/URL will not be handled by Turbo unless they end in a file extension `.htm`, `.html`, `.xhtml`, or `.php`. Turbo will ignore forms and links that target these paths. For example, the following forms would be ignored:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps here we could also explicitly say that if the URL ends in / it will be handled by Turbo. As it is now, if you don't notice the small detail of the final slash you wouldn't notice it. This would allow to put only 4 examples, 2 for those that are handled and 2 for those that aren't. Perhaps giving 4 examples for each case might be a bit excessive?


```html
<form action="/messages.67" method="post">
<!-- ignored -->
</form>

<form action="/somepath/messages.67" method="post">
<!-- also ignored -->
</form>

<form action="/messages.php.1" method="post" data-turbo="true">
<!-- also ignored -->
</form>

<form action="/messages.json" method="post" data-turbo="true">
<!-- also ignored -->
</form>
```

The following forms would be handled:

```html
<form action="/messages/67" method="post">
<!-- handled -->
</form>

<form action="/messages.67/action" method="post">
<!-- also handled -->
</form>

<form action="/messages.php" method="post" data-turbo="true">
<!-- also handled -->
</form>

<form action="/messages.json/" method="post" data-turbo="true">
<!-- also handled -->
</form>

<form action="/messages.json/123" method="post" data-turbo="true">
<!-- also handled -->
</form>
```


Setting any `data-turbo` methods (including `data-turbo="true"`) will not override or force Turbo to handle a path if it has a `.` that causes it to be ignored. Paths with a `.` in the top level that do not end in `.htm`, `.html`, `.xhtml`, or `.php` should be reworked on the backend to not include one. Note that some backend frameworks (i.e. Rails) may automatically append parameters/IDs with a `.` such as `/my_path.67`.

<br><br>
2 changes: 1 addition & 1 deletion _source/reference/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: "A reference of everything you can do with element attributes and m

The following data attributes can be applied to elements to customize Turbo's behaviour.

* `data-turbo="false"` disables Turbo Drive on links and forms including descendants. To reenable when an ancestor has opted out, use `data-turbo="true"`. Be careful: when Turbo Drive is disabled, browsers treat link clicks as normal, but [native adapters](/handbook/native) may exit the app.
* `data-turbo="false"` disables Turbo Drive on links and forms including descendants. To reenable when an ancestor has opted out, use `data-turbo="true"`. Be careful: when Turbo Drive is disabled, browsers treat link clicks as normal, but [native adapters](/handbook/native) may exit the app. Note that if Turbo [ignores a path](/handbook/drive#ignored-paths), then setting `data-turbo="true"` will not force/override it to enable.
* `data-turbo-track="reload"` tracks the element's HTML and performs a full page reload when it changes. Typically used to [keep `script` and CSS `link` elements up-to-date](/handbook/drive#reloading-when-assets-change).
* `data-turbo-frame` identifies the Turbo Frame to navigate. Refer to the [Frames documentation](/reference/frames) for further details.
* `data-turbo-action` customizes the [Visit](/handbook/drive#page-navigation-basics) action. Valid values are `replace` or `advance`. Can also be used with Turbo Frames to [promote frame navigations to page visits](/handbook/frames#promoting-a-frame-navigation-to-a-page-visit).
Expand Down