-
Notifications
You must be signed in to change notification settings - Fork 432
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
Let developers access the initiator element in visit/fetch events #750
base: main
Are you sure you want to change the base?
Let developers access the initiator element in visit/fetch events #750
Conversation
An alternative approach to this might be to create a Navigation ID (UUID) that could be dispatched in the details of all events. This would make it possible to track a navigation from I've also noticed that a redirected link creates two visits, but there's no accurate way to determine which is the initial visit and which is the redirect. A consistent Navigation ID could help with this. For example, if |
Any thoughts on this @kevinmcconnell? |
With word that Turbo 8 is in the works, do you have any thoughts on this feature? (or have anything similar in the pipeline?) I think it could be a game-changer for customising View Transitions. |
To successfully communicate with the iOS view, messages need to be of a type supported by the structuredClone algorithm. The new TransferableVisitOptions type ensures that VisitOptions passed to the adapter conform to this type. The StructuredCloneValue type has been created based on https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#supported_types
e2f4fe5
to
49a314c
Compare
Ensure Navigator#currentVisitOptions is always present
49a314c
to
3e49d80
Compare
2ade5c4
to
547f0c7
Compare
Rebased and tidied |
Having played around with this implementation, there appears to be some odd side-effects when navigating frames (at least when promoting frame visits to update the URL bar). Unfortunately it triggers an untracked element mismatch and performs a full page reload. Perhaps the simplest approach would be #695 but as @kevinmcconnell and I discussed in #720 (comment), it would require removing any values that do not conform the the structured clone algorithm at the iOS/Android adapter stage, which would impact backward compatibility. Are there any plans for this in Turbo 8? |
This appears to be an issue on |
This builds on top of #733
As @kevinmcconnell discovered in #720, the naïve approach to dispatching events on links/forms in #695 failed with the iOS adapter because DOM elements cannot be sent over
postMessage
.This pull request aims to provide a safe way to dispatch events on initiating elements, enabling developers to choose how to handle Visits based on the element that triggered them. (See #99). Prior to sending
VisitOptions
to the adapter, non-transferable properties are removed. When creating a Visit, the originalVisitOptions
are reinstated. Ideally the sanitization process would be handled by the iOS adapter (just before callingpostMessage
), but for backwards compatibility, it needs to done at this level.Details
First, it performs type-checking on the options sent to an adapter's
visitProposedToLocation
, ensuring that it conforms to thestructuredClone
algorithm.Navigator#sanitizeVisitOptionsForTransfer
munges the options to satisfy these conditions.During a Visit proposal, the Visit options temporarily stored in
Navigator#proposedVisitOptions
and cleared after the Visit has started. There is a bit of back-and-forth, so here's an outline of the relevant method calls:Navigator#proposeVisit
;Navigator#withTransferableVisitOptions
stores theproposedVisitOptions
, and creates a sanitized version, passing them to…Session#visitProposedToLocation
, which passes the sanitized options to…Adapter#visitProposedToLocation
; the iOS adapter does its thing; theBrowserAdapter
calls…Navigator#startVisit
, which creates aVisit
with theproposedVisitOptions
and starts itNavigator#withTransferableVisitOptions
resets theproposedVisitOptions
propertyAssuming Visits are created through this process, the initiator should be set. If a Visit is somehow created outside this flow, the initiator defaults to
document.documentElement
.There's a potential bug if a Visit proposal errors, andFixed in 3c3c8e3Navigator#startVisit
is called outside of this flow e.g. via Back/Forward: the Navigator might create a Visit with oldproposedVisitOptions
because they're not cleared due to the Visit proposal error. We could fix this using atry/catch/finally
but Visit proposal errors would be silenced by thecatch
.Finally, I'm not totally convinced that the navigator is the correct place to store visit options, but it works, and keeps it relatively contained for now.
Resolves #733
Closes #99
Closes #720