Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: hotwired/turbo
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: github/turbo
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Aug 2, 2022

  1. Allow URL based content-type guessing

    Add `Session.isVisitable` method whitch is
    equivalent of no longer accessible `URL.isHTML`.
    
    This allows `Turbo.session.isVisitable` to be overriden by user and makes possible
    navigation on URL's other than those with trailing slash or HTML extenion.
    f6p committed Aug 2, 2022
    Copy the full SHA
    da2ca9e View commit details

Commits on Sep 19, 2022

  1. Copy the full SHA
    b338581 View commit details
  2. Merge pull request #7 from manuelpuyol/f6p-f6p-remove-is-html

    f6p remove is html
    manuelpuyol authored Sep 19, 2022
    Copy the full SHA
    c16f31a View commit details

Commits on Sep 28, 2022

  1. Cache PageSnapshot with original HTML from the frame's page

    Before this change, when a promoted frame finished its navigation, a visit
    was started and the visit would add a new PageSnapshot to the cache.
    The problem is that this snapshot was looking at a page that was already
    modified by the frame navigation, so the snapshot cache would be incorrect.
    
    With this proposed change, we are taking a PageSnapshot as soon as the frame
    navigation starts, so we guarantee that the page hasn't been modified yet.
    Then, I'm passing this snapshot forward to the Visit and using it as the
    correct cache instead of calculating a new one.
    manuelpuyol committed Sep 28, 2022
    Copy the full SHA
    6c723e4 View commit details
  2. Copy the full SHA
    c5281d5 View commit details
  3. Copy the full SHA
    722e413 View commit details

Commits on Sep 29, 2022

  1. remove only

    manuelpuyol committed Sep 29, 2022
    Copy the full SHA
    b74ab53 View commit details
  2. Copy the full SHA
    e850faa View commit details
  3. Copy the full SHA
    de1ca80 View commit details
  4. Copy the full SHA
    770c827 View commit details

Commits on Sep 30, 2022

  1. Merge pull request #8 from hotwired/main

    sync
    manuelpuyol authored Sep 30, 2022
    Copy the full SHA
    e365004 View commit details
  2. Merge pull request #9 from manuelpuyol/fix-frame-page-cache

    Fix frame page cache
    manuelpuyol authored Sep 30, 2022
    Copy the full SHA
    903f8f7 View commit details

Commits on Oct 25, 2022

  1. Copy the full SHA
    d67a04e View commit details

Commits on Oct 28, 2022

  1. Copy the full SHA
    7325fcc View commit details

Commits on Nov 3, 2022

  1. Merge pull request #10 from manuelpuyol/custom-render-await

    Allow users to define an async custom render function
    manuelpuyol authored Nov 3, 2022
    Copy the full SHA
    60c452a View commit details
  2. Copy the full SHA
    7e8d8a4 View commit details
  3. Merge pull request #11 from manuelpuyol/frame-activation-script

    Don't replace json islands
    manuelpuyol authored Nov 3, 2022
    Copy the full SHA
    51b5992 View commit details

Commits on Nov 4, 2022

  1. Copy the full SHA
    15b5bf5 View commit details

Commits on Nov 8, 2022

  1. add data-skip-event

    manuelpuyol committed Nov 8, 2022
    Copy the full SHA
    d51a11b View commit details
  2. Copy the full SHA
    2f7668f View commit details
  3. Merge pull request #14 from manuelpuyol/cancel-turbo-click-frame2

    Cancel turbo click frame2
    manuelpuyol authored Nov 8, 2022
    Copy the full SHA
    c519ac5 View commit details
  4. update workflow

    manuelpuyol committed Nov 8, 2022
    Copy the full SHA
    1191191 View commit details
  5. quick test

    manuelpuyol committed Nov 8, 2022
    Copy the full SHA
    e4c86f0 View commit details
  6. even faster

    manuelpuyol committed Nov 8, 2022
    Copy the full SHA
    632b833 View commit details
  7. update package

    manuelpuyol committed Nov 8, 2022
    Copy the full SHA
    cd3cf2c View commit details
  8. Copy the full SHA
    9685786 View commit details
  9. 7.1.0

    manuelpuyol committed Nov 8, 2022
    Copy the full SHA
    d8c8fd1 View commit details
  10. 7.2.5

    manuelpuyol committed Nov 8, 2022
    Copy the full SHA
    6085b4b View commit details
  11. add publish workflow

    manuelpuyol committed Nov 8, 2022
    Copy the full SHA
    e441b12 View commit details
  12. fix idnent

    manuelpuyol committed Nov 8, 2022
    Copy the full SHA
    6150ac8 View commit details
  13. use - instead of .

    manuelpuyol committed Nov 8, 2022
    Copy the full SHA
    238648a View commit details
  14. add cache

    manuelpuyol committed Nov 8, 2022
    Copy the full SHA
    95e2a53 View commit details
  15. Merge pull request #15 from manuelpuyol/workflows

    Release versions for each PR
    manuelpuyol authored Nov 8, 2022
    Copy the full SHA
    1b48ad3 View commit details
  16. publish next

    manuelpuyol committed Nov 8, 2022
    Copy the full SHA
    422d599 View commit details
  17. Merge pull request #16 from manuelpuyol/beta-workflow

    publish next
    manuelpuyol authored Nov 8, 2022
    Copy the full SHA
    0d538d7 View commit details

Commits on Nov 9, 2022

  1. add test about issue #604

    manuelpuyol committed Nov 9, 2022
    Copy the full SHA
    ed2b52e View commit details
  2. Copy the full SHA
    3f5c676 View commit details
  3. Merge pull request #17 from hotwired/main

    Fix: Promoting lazy-loaded Frames (#790)
    manuelpuyol authored Nov 9, 2022
    Copy the full SHA
    5de0835 View commit details

Commits on Nov 14, 2022

  1. Merge pull request #18 from manuelpuyol/issue-604

    Issue 604
    manuelpuyol authored Nov 14, 2022
    Copy the full SHA
    115442c View commit details

Commits on Jan 24, 2023

  1. Redirect to Location with a URL hash

    This pull request adds test coverage to demonstrate a limitation in
    Turbo's support for redirecting to a URL with a [hash][] value.
    
    Currently, redirecting to a URL with a hash (for example,
    `/src/tests/fixtures/one.html#element-id`) omits the hash
    (`#element-id`) when navigating to the final destination.
    
    According to the [fetch specification][], redirects should preserve URL
    fragments during redirection.
    
    [hash]: https://developer.mozilla.org/en-US/docs/Web/API/URL/hash
    [fetch specification]: https://fetch.spec.whatwg.org/#http-redirect-fetch
    seanpdoyle authored and manuelpuyol committed Jan 24, 2023
    Copy the full SHA
    3ac4286 View commit details
  2. Copy the full SHA
    b359c66 View commit details
  3. hard example

    manuelpuyol committed Jan 24, 2023
    Copy the full SHA
    10f788b View commit details
  4. Copy the full SHA
    e1fb390 View commit details
  5. Copy the full SHA
    c38555e View commit details

Commits on Feb 2, 2023

  1. reorder links for tests

    manuelpuyol committed Feb 2, 2023
    Copy the full SHA
    43b611f View commit details

Commits on Feb 15, 2023

  1. allow tests on prs

    manuelpuyol committed Feb 15, 2023
    Copy the full SHA
    c90ed44 View commit details
  2. Copy the full SHA
    1027999 View commit details
  3. update playwright

    manuelpuyol committed Feb 15, 2023
    Copy the full SHA
    a194e7d View commit details
  4. Copy the full SHA
    4dfb408 View commit details
  5. add example with images

    manuelpuyol committed Feb 15, 2023
    Copy the full SHA
    95a9a3a View commit details
Showing with 1,073 additions and 442 deletions.
  1. +1 −1 .devcontainer/devcontainer.json
  2. +3 −6 .github/workflows/ci.yml
  3. +38 −0 .github/workflows/publish-beta.yml
  4. +1 −0 CODEOWNERS
  5. +31 −0 SECURITY.md
  6. +4 −4 package.json
  7. +4 −0 playwright.config.ts
  8. +2 −2 src/core/bardo.ts
  9. +1 −0 src/core/drive/error_renderer.ts
  10. +3 −1 src/core/drive/history.ts
  11. +13 −6 src/core/drive/navigator.ts
  12. +8 −6 src/core/drive/page_renderer.ts
  13. +11 −1 src/core/drive/page_snapshot.ts
  14. +1 −1 src/core/drive/preloader.ts
  15. +16 −12 src/core/drive/visit.ts
  16. +56 −11 src/core/frames/frame_controller.ts
  17. +16 −5 src/core/frames/frame_redirector.ts
  18. +15 −1 src/core/frames/frame_renderer.ts
  19. +1 −1 src/core/frames/frame_view.ts
  20. +2 −0 src/core/index.ts
  21. +2 −2 src/core/renderer.ts
  22. +13 −4 src/core/session.ts
  23. +2 −0 src/core/streams/stream_message.ts
  24. +0 −8 src/core/url.ts
  25. +8 −1 src/elements/frame_element.ts
  26. +1 −0 src/index.ts
  27. +4 −0 src/tests/fixtures/form.html
  28. +1 −1 src/tests/fixtures/frames.html
  29. BIN src/tests/fixtures/images/turbo.png
  30. +4 −0 src/tests/fixtures/navigation.html
  31. +1 −0 src/tests/fixtures/tabs.html
  32. +22 −8 src/tests/fixtures/tabs/three.html
  33. +21 −8 src/tests/fixtures/tabs/two.html
  34. +24 −0 src/tests/fixtures/tabs/with-image.html
  35. +11 −10 src/tests/fixtures/test.js
  36. +16 −0 src/tests/fixtures/visitable.html
  37. +1 −0 src/tests/functional/async_script_tests.ts
  38. +1 −0 src/tests/functional/autofocus_tests.ts
  39. +1 −0 src/tests/functional/cache_observer_tests.ts
  40. +1 −0 src/tests/functional/drive_disabled_tests.ts
  41. +1 −0 src/tests/functional/drive_tests.ts
  42. +1 −0 src/tests/functional/form_mode_tests.ts
  43. +11 −0 src/tests/functional/form_submission_tests.ts
  44. +59 −1 src/tests/functional/frame_navigation_tests.ts
  45. +11 −0 src/tests/functional/frame_tests.ts
  46. +1 −0 src/tests/functional/import_tests.ts
  47. +1 −0 src/tests/functional/loading_tests.ts
  48. +11 −0 src/tests/functional/navigation_tests.ts
  49. +52 −0 src/tests/functional/page_snapshot_tests.ts
  50. +1 −0 src/tests/functional/pausable_rendering_tests.ts
  51. +1 −0 src/tests/functional/pausable_requests_tests.ts
  52. +1 −0 src/tests/functional/preloader_tests.ts
  53. +31 −0 src/tests/functional/rendering_tests.ts
  54. +1 −0 src/tests/functional/scroll_restoration_tests.ts
  55. +1 −0 src/tests/functional/stream_tests.ts
  56. +1 −0 src/tests/functional/ujs_tests.ts
  57. +1 −0 src/tests/functional/visit_tests.ts
  58. +32 −0 src/tests/functional/visitable_tests.ts
  59. +1 −1 src/tests/helpers/page.ts
  60. +19 −0 src/tests/helpers/trusted_type_setup.ts
  61. +4 −1 src/tests/runner.js
  62. +2 −2 src/tests/server.ts
  63. +1 −0 src/tests/unit/index.ts
  64. +53 −0 src/tests/unit/util_tests.ts
  65. +36 −0 src/trusted_types.ts
  66. +30 −2 src/util.ts
  67. +348 −335 yarn.lock
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "yarn install && yarn build",
"postCreateCommand": "yarn install && yarn build && yarn run playwright install",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node"
}
9 changes: 3 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
name: CI

on: [push, pull_request]
on: [push]

jobs:
build:

runs-on: ubuntu-latest


steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
@@ -40,6 +38,5 @@ jobs:
- name: Firefox Test
run: yarn test:browser --project=firefox

- name: Publish dev build
run: .github/scripts/publish-dev-build '${{ secrets.DEV_BUILD_GITHUB_TOKEN }}'
if: ${{ github.event_name == 'push' }}
- name: Chrome With Trusted Types Test
run: yarn test:browser --project=chrome-with-trusted-types
38 changes: 38 additions & 0 deletions .github/workflows/publish-beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Publish Beta Package to npmjs
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
registry-url: 'https://registry.npmjs.org'
- uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- run: yarn install

- name: Update version
run: |
version=$(jq -r .version package.json)-$(git rev-parse --short HEAD)
echo "$(jq --arg v "${version}" '.version = $v' package.json)" > package.json
- run: yarn build

- run: npm publish --tag next
if: github.ref == 'refs/heads/main'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- run: npm publish --tag $(git rev-parse --short HEAD)
if: github.event_name == 'workflow_dispatch'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @github/web-systems-reviewers
31 changes: 31 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Thanks for helping make GitHub safe for everyone.

## Security

GitHub takes the security of our software products and services seriously, including all of the open source code repositories managed through our GitHub organizations, such as [GitHub](https://github.com/GitHub).

Even though [open source repositories are outside of the scope of our bug bounty program](https://bounty.github.com/index.html#scope) and therefore not eligible for bounty rewards, we will ensure that your finding gets passed along to the appropriate maintainers for remediation.

## Reporting Security Issues

If you believe you have found a security vulnerability in any GitHub-owned repository, please report it to us through coordinated disclosure.

**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**

Instead, please send an email to opensource-security[@]github.com.

Please include as much of the information listed below as you can to help us better understand and resolve the issue:

* The type of issue (e.g., buffer overflow, SQL injection, or cross-site scripting)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue

This information will help us triage your report more quickly.

## Policy

See [GitHub's Safe Harbor Policy](https://docs.github.com/en/site-policy/security-policies/github-bug-bounty-program-legal-safe-harbor)
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hotwired/turbo",
"version": "7.2.4",
"name": "@github/turbo",
"version": "7.2.9",
"description": "The speed of a single-page web application without having to write any JavaScript",
"module": "dist/turbo.es2017-esm.js",
"main": "dist/turbo.es2017-umd.js",
@@ -35,7 +35,7 @@
"access": "public"
},
"devDependencies": {
"@playwright/test": "^1.22.2",
"@playwright/test": "^1.40.1",
"@rollup/plugin-node-resolve": "13.1.3",
"@rollup/plugin-typescript": "^8.5.0",
"@types/multer": "^1.4.5",
@@ -46,7 +46,7 @@
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"intern": "^4.9.0",
"intern": "^4.10.1",
"multer": "^1.4.2",
"prettier": "2.6.2",
"rollup": "^2.35.1",
4 changes: 4 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,10 @@ const config: PlaywrightTestConfig = {
name: "firefox",
use: { ...devices["Desktop Firefox"] },
},
{
name: "chrome-with-trusted-types",
use: { ...devices["Desktop Chrome"] },
},
],
retries: 2,
testDir: "./src/tests/functional",
4 changes: 2 additions & 2 deletions src/core/bardo.ts
Original file line number Diff line number Diff line change
@@ -9,14 +9,14 @@ export class Bardo {
readonly permanentElementMap: PermanentElementMap
readonly delegate: BardoDelegate

static preservingPermanentElements(
static async preservingPermanentElements(
delegate: BardoDelegate,
permanentElementMap: PermanentElementMap,
callback: () => void
) {
const bardo = new this(delegate, permanentElementMap)
bardo.enter()
callback()
await callback()
bardo.leave()
}

1 change: 1 addition & 0 deletions src/core/drive/error_renderer.ts
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ export class ErrorRenderer extends Renderer<HTMLBodyElement, PageSnapshot> {

activateScriptElements() {
for (const replaceableElement of this.scriptElements) {
if (replaceableElement.type === "application/json") continue
const parentNode = replaceableElement.parentNode
if (parentNode) {
const element = activateScriptElement(replaceableElement)
4 changes: 3 additions & 1 deletion src/core/drive/history.ts
Original file line number Diff line number Diff line change
@@ -21,6 +21,8 @@ export class History {
started = false
pageLoaded = false
previousScrollRestoration?: ScrollRestoration
// This can be customized by the consumer
shouldRestore: (state: any) => boolean = () => true

constructor(delegate: HistoryDelegate) {
this.delegate = delegate
@@ -94,7 +96,7 @@ export class History {
onPopState = (event: PopStateEvent) => {
if (this.shouldHandlePopState()) {
const { turbo } = event.state || {}
if (turbo) {
if (this.shouldRestore(event.state) && turbo) {
this.location = new URL(window.location.href)
const { restorationIdentifier } = turbo
this.restorationIdentifier = restorationIdentifier
19 changes: 13 additions & 6 deletions src/core/drive/navigator.ts
Original file line number Diff line number Diff line change
@@ -2,14 +2,15 @@ import { Action, isAction } from "../types"
import { FetchMethod } from "../../http/fetch_request"
import { FetchResponse } from "../../http/fetch_response"
import { FormSubmission } from "./form_submission"
import { expandURL, getAnchor, getRequestURL, Locatable, locationIsVisitable } from "../url"
import { expandURL, getAnchor, getRequestURL, Locatable } from "../url"
import { getAttribute } from "../../util"
import { Visit, VisitDelegate, VisitOptions } from "./visit"
import { PageSnapshot } from "./page_snapshot"

export type NavigatorDelegate = VisitDelegate & {
allowsVisitingLocationWithAction(location: URL, action?: Action): boolean
visitProposedToLocation(location: URL, options: Partial<VisitOptions>): void
locationIsVisitable(location: URL, rootLocation: URL): boolean
notifyApplicationAfterVisitingSamePageLocation(oldURL: URL, newURL: URL): void
}

@@ -24,7 +25,7 @@ export class Navigator {

proposeVisit(location: URL, options: Partial<VisitOptions> = {}) {
if (this.delegate.allowsVisitingLocationWithAction(location, options.action)) {
if (locationIsVisitable(location, this.view.snapshot.rootLocation)) {
if (this.delegate.locationIsVisitable(location, this.view.snapshot.rootLocation)) {
this.delegate.visitProposedToLocation(location, options)
} else {
window.location.href = location.toString()
@@ -90,14 +91,19 @@ export class Navigator {
this.view.clearSnapshotCache()
}

const { statusCode, redirected } = fetchResponse
const { statusCode, redirected, response } = fetchResponse
const action = this.getActionForFormSubmission(formSubmission)
const visitOptions = {
action,
shouldCacheSnapshot,
response: { statusCode, responseHTML, redirected },
response: { statusCode, redirected, response, responseHTML },
}
this.proposeVisit(fetchResponse.location, visitOptions)

const location = fetchResponse.location
if (redirected && fetchResponse.location.hash === "") {
location.hash = formSubmission.fetchRequest.location.hash
}
this.proposeVisit(location, visitOptions)
}
}
}
@@ -106,7 +112,8 @@ export class Navigator {
const responseHTML = await fetchResponse.responseHTML

if (responseHTML) {
const snapshot = PageSnapshot.fromHTMLString(responseHTML)
const snapshot = PageSnapshot.fromResponse(fetchResponse.response, responseHTML)

if (fetchResponse.serverError) {
await this.view.renderError(snapshot, this.currentVisit)
} else {
14 changes: 8 additions & 6 deletions src/core/drive/page_renderer.ts
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ export class PageRenderer extends Renderer<HTMLBodyElement, PageSnapshot> {

async render() {
if (this.willRender) {
this.replaceBody()
await this.replaceBody()
}
}

@@ -67,10 +67,10 @@ export class PageRenderer extends Renderer<HTMLBodyElement, PageSnapshot> {
await newStylesheetElements
}

replaceBody() {
this.preservingPermanentElements(() => {
async replaceBody() {
await this.preservingPermanentElements(async () => {
this.activateNewBody()
this.assignNewBody()
await this.assignNewBody()
})
}

@@ -115,13 +115,15 @@ export class PageRenderer extends Renderer<HTMLBodyElement, PageSnapshot> {

activateNewBodyScriptElements() {
for (const inertScriptElement of this.newBodyScriptElements) {
if (inertScriptElement.type === "application/json") continue

const activatedScriptElement = activateScriptElement(inertScriptElement)
inertScriptElement.replaceWith(activatedScriptElement)
}
}

assignNewBody() {
this.renderElement(this.currentElement, this.newElement)
async assignNewBody() {
await this.renderElement(this.currentElement, this.newElement)
}

get newHeadStylesheetElements() {
12 changes: 11 additions & 1 deletion src/core/drive/page_snapshot.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { CSPTrustedTypesPolicy, emptyHTML } from "../../trusted_types"
import { parseHTMLDocument } from "../../util"
import { Snapshot } from "../snapshot"
import { expandURL } from "../url"
import { HeadSnapshot } from "./head_snapshot"

export class PageSnapshot extends Snapshot<HTMLBodyElement> {
static fromHTMLString(html = "") {
static fromResponse(response?: Response, html = emptyHTML): PageSnapshot {
if (!response || CSPTrustedTypesPolicy == null) {
return this.fromHTMLString(html)
}

const trustedHTML = CSPTrustedTypesPolicy.createHTML(html, response)
return this.fromHTMLString(trustedHTML as string)
}

static fromHTMLString(html = emptyHTML) {
return this.fromDocument(parseHTMLDocument(html))
}

2 changes: 1 addition & 1 deletion src/core/drive/preloader.ts
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ export class Preloader {
try {
const response = await fetch(location.toString(), { headers: { "VND.PREFETCH": "true", Accept: "text/html" } })
const responseText = await response.text()
const snapshot = PageSnapshot.fromHTMLString(responseText)
const snapshot = PageSnapshot.fromResponse(response, responseText)

this.snapshotCache.put(location, snapshot)
} catch (_) {
28 changes: 16 additions & 12 deletions src/core/drive/visit.ts
Original file line number Diff line number Diff line change
@@ -67,6 +67,7 @@ const defaultOptions: VisitOptions = {
export type VisitResponse = {
statusCode: number
redirected: boolean
response?: Response
responseHTML?: string
}

@@ -253,17 +254,17 @@ export class Visit implements FetchRequestDelegate {

loadResponse() {
if (this.response) {
const { statusCode, responseHTML } = this.response
const { statusCode, response, responseHTML } = this.response
this.render(async () => {
if (this.shouldCacheSnapshot) this.cacheSnapshot()
if (this.view.renderPromise) await this.view.renderPromise
if (isSuccessful(statusCode) && responseHTML != null) {
await this.view.renderPage(PageSnapshot.fromHTMLString(responseHTML), false, this.willRender, this)
await this.view.renderPage(PageSnapshot.fromResponse(response, responseHTML), false, this.willRender, this)
this.performScroll()
this.adapter.visitRendered(this)
this.complete()
} else {
await this.view.renderError(PageSnapshot.fromHTMLString(responseHTML), this)
await this.view.renderError(PageSnapshot.fromResponse(response, responseHTML), this)
this.adapter.visitRendered(this)
this.fail()
}
@@ -347,30 +348,33 @@ export class Visit implements FetchRequestDelegate {

requestPreventedHandlingResponse(_request: FetchRequest, _response: FetchResponse) {}

async requestSucceededWithResponse(request: FetchRequest, response: FetchResponse) {
const responseHTML = await response.responseHTML
const { redirected, statusCode } = response
async requestSucceededWithResponse(request: FetchRequest, fetchResponse: FetchResponse) {
const responseHTML = await fetchResponse.responseHTML
const { redirected, statusCode, response } = fetchResponse
if (responseHTML == undefined) {
this.recordResponse({
statusCode: SystemStatusCode.contentTypeMismatch,
redirected,
})
} else {
this.redirectedToLocation = response.redirected ? response.location : undefined
this.recordResponse({ statusCode: statusCode, responseHTML, redirected })
this.redirectedToLocation = fetchResponse.redirected ? fetchResponse.location : undefined
if (this.redirectedToLocation && fetchResponse.location.hash === "") {
this.redirectedToLocation.hash = request.url.hash
}
this.recordResponse({ statusCode: statusCode, redirected, response, responseHTML })
}
}

async requestFailedWithResponse(request: FetchRequest, response: FetchResponse) {
const responseHTML = await response.responseHTML
const { redirected, statusCode } = response
async requestFailedWithResponse(request: FetchRequest, fetchResponse: FetchResponse) {
const responseHTML = await fetchResponse.responseHTML
const { redirected, statusCode, response } = fetchResponse
if (responseHTML == undefined) {
this.recordResponse({
statusCode: SystemStatusCode.contentTypeMismatch,
redirected,
})
} else {
this.recordResponse({ statusCode: statusCode, responseHTML, redirected })
this.recordResponse({ statusCode: statusCode, redirected, response, responseHTML })
}
}

Loading