Skip to content

Commit

Permalink
chore: Use sessionStorage to store requested turbo frame
Browse files Browse the repository at this point in the history
  • Loading branch information
julianrubisch committed Jul 8, 2024
1 parent a998ebf commit c8c92aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion javascript/elements/futurism_utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global IntersectionObserver, CustomEvent, setTimeout */

const dispatchAppearEvent = (entry, observer = null) => {
if (!window.Futurism) {
if (!window.Futurism?.subscription) {
return () => {
setTimeout(() => dispatchAppearEvent(entry, observer)(), 1)
}
Expand Down
6 changes: 3 additions & 3 deletions javascript/elements/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ const restorePlaceholders = e => {
// if the TF request has been promoted to an advance action
// (data-turbo-action="advance"), this callback will fire inadvertently
// but the whole page will not be exchanged as in a regular TD visit
if (window.Futurism.requestedTurboFrame) {
delete window.Futurism.requestedTurboFrame
if (sessionStorage.getItem('requested-turbo-frame')) {
delete sessionStorage.removeItem('requested-turbo-frame')
return
}

Expand All @@ -87,7 +87,7 @@ const storeRequestedTurboFrame = e => {
if (!headers['Turbo-Frame'] || headers['X-Sec-Purpose'] === 'prefetch') return

// we store the frame ID in case the incoming request was referencing one
window.Futurism.requestedTurboFrame = headers['Turbo-Frame']
sessionStorage.setItem('requested-turbo-frame', headers['Turbo-Frame'])
}

export const initializeElements = () => {
Expand Down

0 comments on commit c8c92aa

Please sign in to comment.