Proposal: pass isPreview value into the event detail in render events#926
Merged
afcapel merged 1 commit intohotwired:mainfrom Aug 24, 2023
Merged
Conversation
…nd 'turbo:render' events. isPreview signifies whether the content currently being rendered is from the turbo cache or not, and this bit of information is very useful for any listeners that might want to act on those two events differently for cached or non-cached content.
Collaborator
|
Looks good, thanks @Matt-Yorkley 👍 |
Contributor
|
Could this be inferred from document.addEventListener("turbo:before-render", () => {
console.log("turbo:before-render")
console.log(document.documentElement.hasAttribute('data-turbo-preview'))
})
document.addEventListener("turbo:render", () => {
console.log("turbo:render")
console.log(document.documentElement.hasAttribute('data-turbo-preview'))
}) |
Collaborator
|
@Matt-Yorkley @domchristie is making a good point. Can you use |
Contributor
Author
Ah, I must have missed |
domchristie
added a commit
to domchristie/turbo
that referenced
this pull request
Jan 9, 2024
It is not necessary to pass along isPreview through various methods in order to determine whether a render is a preview since that can be determined via the data-turbo-preview attribute. (As discussed in hotwired#926 (comment))
domchristie
added a commit
to domchristie/turbo
that referenced
this pull request
Jan 9, 2024
It is not necessary to pass along isPreview through various methods in order to determine whether a render is a preview since that can be determined via the data-turbo-preview attribute. (As discussed in hotwired#926 (comment))
afcapel
pushed a commit
that referenced
this pull request
Jan 22, 2024
afcapel
added a commit
to pfeiffer/turbo
that referenced
this pull request
Jan 29, 2024
* origin/main:
Introduce `turbo:{before-,}morph-{element,attribute}` events
Turbo 8.0.0-beta.4
Introduce data-turbo-track="dynamic" (hotwired#1140)
Ensure that the turbo-frame header is not sent when the turbo-frame has a target of _top (hotwired#1138)
Turbo 8.0.0-beta.3
Fix attribute name (hotwired#1134)
Add InstantClick behavior (hotwired#1101)
Revert hotwired#926. (hotwired#1126)
Keep Trix dynamic styles in the head (hotwired#1133)
Remove unused stylesheets when navigating (hotwired#1128)
Upgrade idiomorph to 0.3.0 (hotwired#1122)
Debounce page refreshes triggered via Turbo streams
Update copyright year to 2024 (hotwired#1118)
Turbo 8.0.0-beta.2
Set aria-busy on the form element during a form submission (hotwired#1110)
Dispatch `turbo:before-fetch-{request,response}` during preloading (hotwired#1034)
ippachi
added a commit
to ippachi/turbo-site
that referenced
this pull request
May 18, 2024
isPreview is reverted (discussed in hotwired/turbo#926)
domchristie
added a commit
to domchristie/turbo
that referenced
this pull request
Jul 20, 2024
It is not necessary to pass along isPreview through various methods in order to determine whether a render is a preview since that can be determined via the data-turbo-preview attribute. (As discussed in hotwired#926 (comment))
Challenge-Guy
pushed a commit
to Challenge-Guy/turbo-cfm1
that referenced
this pull request
Mar 8, 2025
It is not necessary to pass along isPreview through various methods in order to determine whether a render is a preview since that can be determined via the data-turbo-preview attribute. (As discussed in hotwired/turbo#926 (comment))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Passes the renderer's
isPreviewattribute into the event detail on'turbo:before-render'and'turbo:render'events.isPreviewsignifies whether the content currently being rendered is from the turbo cache or not, and this bit of information is very useful for any listeners that might want to act on those two events differently for cached or non-cached content.Eg, the following listeners:
now produce these event details (when navigating to a page that has a cache entry, both events fire twice):

So it's now possible to do things like...