From 476eca4b842871e3cb03944639dc47bd2467916f Mon Sep 17 00:00:00 2001 From: Jeffrey Hardy Date: Wed, 15 Feb 2023 09:37:24 -0500 Subject: [PATCH] Document [data-turbo-temporary] as the replacement of [data-turbo-cache=false] References: - https://github.com/hotwired/turbo/pull/871 --- _source/handbook/06_building.md | 11 ++++++++++- _source/reference/attributes.md | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/_source/handbook/06_building.md b/_source/handbook/06_building.md index d64c2e2..e23a508 100644 --- a/_source/handbook/06_building.md +++ b/_source/handbook/06_building.md @@ -54,7 +54,16 @@ document.addEventListener("turbo:before-cache", function() { }) ``` -Annotate elements with `data-turbo-cache="false"` if you do not want Turbo to cache them. This is helpful for temporary elements, like flash notices. +Certain page elements are inherently _temporary_, like flash messages or alerts. If they’re cached with the document they’ll be redisplayed when it’s restored, which is rarely desirable. You can annotate such elements with `data-turbo-temporary` to have Turbo Drive automatically remove them from the page before it’s cached. + +```html + +
+ Your cart was updated! +
+ ... + +``` ### Detecting When a Preview is Visible diff --git a/_source/reference/attributes.md b/_source/reference/attributes.md index 5e73508..27ed1d0 100644 --- a/_source/reference/attributes.md +++ b/_source/reference/attributes.md @@ -16,7 +16,7 @@ The following data attributes can be applied to elements to customize Turbo's be * `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). * `data-turbo-permanent` [persists the element between page loads](/handbook/building#persisting-elements-across-page-loads). The element must have a unique `id` attribute. -* `data-turbo-cache="false"` removes the element before the document is cached, preventing it from reappearing on restoration Visits. +* `data-turbo-temporary` removes the element before the document is cached, preventing it from reappearing when restored. * `data-turbo-eval="false"` prevents inline `script` elements from being re-evaluated on Visits. * `data-turbo-method` changes the link request type from the default `GET`. Ideally, non-`GET` requests should be triggered with forms, but `data-turbo-method` might be useful where a form is not possible. * `data-turbo-stream` specifies that a link or form can accept a Turbo Streams response. Turbo [automatically requests stream responses](/handbook/streams#streaming-from-http-responses) for form submissions with non-`GET` methods; `data-turbo-stream` allows Turbo Streams to be used with `GET` requests as well.