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 43c707a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 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> {
console.warn(`Completing full-page visit as matching frame for #${frame.id} was missing from the response`)
return this.visit(fetchResponse.location)
async frameMissing(frame: FrameElement, fetchResponse: FetchResponse): Promise<void> {
console.warn(`A matching frame for #${frame.id} was missing from the response, transforming into full-page Visit.`)

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 43c707a

Please sign in to comment.