Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/drive/prefetch_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PrefetchCache extends LRUCache {

putLater(url, request, ttl) {
this.#prefetchTimeout = setTimeout(() => {
request.perform()
request.perform().catch(() => this.evict(toCacheKey(url)))
this.put(url, request, ttl)
this.#prefetchTimeout = null
}, this.prefetchDelay)
Expand Down
19 changes: 19 additions & 0 deletions src/tests/functional/link_prefetch_observer_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,25 @@ test("doesn't include a turbo-frame header when the link is inside a turbo frame
}})
})

test("it doesn't cause an unhandled rejection when a prefetch request fails", async ({ page }) => {
await goTo({ page, path: "/hover_to_prefetch.html" })

await page.evaluate(() => {
window.__unhandledRejections = []
window.addEventListener("unhandledrejection", (event) => {
window.__unhandledRejections.push(event.reason?.message ?? String(event.reason))
})
})

await page.route("**/prefetched.html", (route) => route.abort("failed"))

await page.hover("#anchor_for_prefetch")
await sleep(200)

const unhandledRejections = await page.evaluate(() => window.__unhandledRejections)
expect(unhandledRejections).toHaveLength(0)
})

test("it prefetches links with a delay", async ({ page }) => {
await goTo({ page, path: "/hover_to_prefetch.html" })

Expand Down