native prefetch

This commit is contained in:
Pete Matsyburka committed 2026-09-23 11:00:17 +03:00
1 parent f5dad673de
commit 79aa034183
1 file changed
+16
+16
View File
@@ -113,6 +113,20 @@ if (handlers?.native && window === window.top) {
handlers.modal.postMessage({ action: 'open', url: link.href, modal: link.closest('[data-native-modal]')?.dataset.nativeModal || '' })
}, true)
let isTouchPrefetch = false
document.addEventListener('touchstart', (event) => {
isTouchPrefetch = true
event.target.closest('a[href]')?.dispatchEvent(new MouseEvent('mouseenter'))
isTouchPrefetch = false
}, { passive: true })
document.addEventListener('turbo:before-prefetch', (event) => {
if (!isTouchPrefetch || event.target.closest('a[data-turbo-frame="modal"], a[data-turbo-frame="drawer"]')) {
event.preventDefault()
}
})
document.addEventListener('native:action', (event) => {
document.querySelector(`[data-native-id="${event.detail.id}"]`)?.click()
})
@@ -132,6 +146,8 @@ if (handlers?.native && window.Turbo) {
this.snapshotCache.keys.forEach((key) => staleSnapshots.add(key))
}
window.Turbo.session.navigator.linkPrefetchingIsEnabledForLocation = () => !document.querySelector('native-modal')
document.addEventListener('turbo:submit-end', (e) => {
if (e.detail.success && !e.detail.formSubmission.isSafe) {
handlers.native.postMessage({ type: 'stale' })