Skip to content

Commit c18f894

Browse files
committed
turbo:frame-missing: Re-use FetchResponse HTML
After re-considering a comment on [hotwired#445][], this commit re-purposes the response HTML from the `FetchResponse` instance, instead of issuing a follow-up HTTP request. [hotwired#445]: hotwired#445 (comment)
1 parent c4e0aba commit c18f894

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/core/session.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,13 @@ export class Session
309309
this.notifyApplicationAfterFrameRender(fetchResponse, frame)
310310
}
311311

312-
frameMissing(frame: FrameElement, fetchResponse: FetchResponse): Promise<void> {
312+
async frameMissing(frame: FrameElement, fetchResponse: FetchResponse): Promise<void> {
313313
console.warn(`Completing full-page visit as matching frame for #${frame.id} was missing from the response`)
314-
return this.visit(fetchResponse.location)
314+
315+
const responseHTML = await fetchResponse.responseHTML
316+
const { location, redirected, statusCode } = fetchResponse
317+
318+
return this.visit(location, { response: { redirected, statusCode, responseHTML } })
315319
}
316320

317321
// Application events

src/tests/functional/frame_tests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ test("test following a link to a page without a matching frame dispatches a turb
120120
await noNextEventOnTarget(page, "missing", "turbo:frame-render")
121121
await noNextEventOnTarget(page, "missing", "turbo:frame-load")
122122
const { fetchResponse } = await nextEventOnTarget(page, "missing", "turbo:frame-missing")
123+
await noNextEventNamed(page, "turbo:before-fetch-request")
123124
await nextEventNamed(page, "turbo:load")
124125

125126
assert.ok(fetchResponse, "dispatchs turbo:frame-missing with event.detail.fetchResponse")

0 commit comments

Comments
 (0)