Skip to content

Commit

Permalink
Restore asynchronous Page rendering
Browse files Browse the repository at this point in the history
Restore the asynchronous rendering by awaiting `nextAnimationFrame` from
within the `View.renderSnapshot` method instead of awaiting a
`nextEventLoopTick` from within the `PageRenderer.renderElement` method.
  • Loading branch information
seanpdoyle committed Sep 14, 2022
1 parent 4c77a4c commit 3151587
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/core/drive/page_renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Renderer } from "../renderer"
import { PageSnapshot } from "./page_snapshot"
import { ReloadReason } from "../native/browser_adapter"
import { activateScriptElement, waitForLoad, getBodyElementId } from "../../util"
import { nextEventLoopTick } from "../../util"

export class PageRenderer extends Renderer<HTMLBodyElement, PageSnapshot> {
static renderElement(currentElement: HTMLBodyElement, newElement: HTMLBodyElement) {
Expand Down Expand Up @@ -38,6 +39,8 @@ export class PageRenderer extends Renderer<HTMLBodyElement, PageSnapshot> {
}

async render() {
await nextEventLoopTick()

if (this.willRender) {
this.replaceBody()
}
Expand Down
29 changes: 19 additions & 10 deletions src/tests/functional/drive_custom_body_tests.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import { test } from "@playwright/test"
import { assert } from "chai"
import { nextBody, pathname } from "../helpers/page"

const path = "/src/tests/fixtures/drive_custom_body.html"
import { nextEventNamed, pathname } from "../helpers/page"

test.beforeEach(async ({ page }) => {
await page.goto(path)
await page.goto("/src/tests/fixtures/drive_custom_body.html")
})

test("test drive with a custom body element", async ({ page }) => {
page.click("#drive")
await nextBody(page)
await page.click("#drive")
await nextEventNamed(page, "turbo:load")

assert.equal(pathname(page.url()), "/src/tests/fixtures/drive_custom_body_2.html")
assert.equal(await page.textContent("h1"), "Drive (with custom body)")
assert.equal(await page.textContent("#different-content"), "Drive 2")

await page.goBack()
await nextEventNamed(page, "turbo:load")

assert.equal(pathname(page.url()), "/src/tests/fixtures/drive_custom_body.html")
assert.equal(await page.textContent("h1"), "Drive (with custom body)")
assert.equal(await page.textContent("#different-content"), "Drive 1")

const h1 = await page.locator("h1")
const differentContent = await page.locator("#different-content")
await page.goForward()
await nextEventNamed(page, "turbo:load")

assert.equal(pathname(page.url()), "/src/tests/fixtures/drive_custom_body_2.html")
assert.equal(await h1.textContent(), "Drive (with custom body)")
assert.equal(await differentContent.textContent(), "Drive 2")
assert.equal(await page.textContent("h1"), "Drive (with custom body)")
assert.equal(await page.textContent("#different-content"), "Drive 2")
})

0 comments on commit 3151587

Please sign in to comment.