Skip to content

Commit

Permalink
turbo:frame-missing: Re-use FetchResponse HTML
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
seanpdoyle committed Aug 8, 2022
1 parent c4e0aba commit c18f894
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,13 @@ export class Session
this.notifyApplicationAfterFrameRender(fetchResponse, frame)
}

frameMissing(frame: FrameElement, fetchResponse: FetchResponse): Promise<void> {
async frameMissing(frame: FrameElement, fetchResponse: FetchResponse): Promise<void> {
console.warn(`Completing full-page visit as matching frame for #${frame.id} was missing from the response`)
return this.visit(fetchResponse.location)

const responseHTML = await fetchResponse.responseHTML
const { location, redirected, statusCode } = fetchResponse

return this.visit(location, { response: { redirected, statusCode, responseHTML } })
}

// Application events
Expand Down
1 change: 1 addition & 0 deletions src/tests/functional/frame_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ test("test following a link to a page without a matching frame dispatches a turb
await noNextEventOnTarget(page, "missing", "turbo:frame-render")
await noNextEventOnTarget(page, "missing", "turbo:frame-load")
const { fetchResponse } = await nextEventOnTarget(page, "missing", "turbo:frame-missing")
await noNextEventNamed(page, "turbo:before-fetch-request")
await nextEventNamed(page, "turbo:load")

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

0 comments on commit c18f894

Please sign in to comment.