Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
It is not necessary to pass along isPreview through various methods in order to determine whether a render is a preview since that can be determined via the data-turbo-preview attribute. (As discussed in hotwired#926 (comment))
  • Loading branch information
domchristie committed Jul 15, 2024
1 parent 456816b commit 3ce4849
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/core/frames/frame_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export class FrameController {

// View delegate

allowsImmediateRender({ element: newFrame }, _isPreview, options) {
allowsImmediateRender({ element: newFrame }, options) {
const event = dispatch("turbo:before-frame-render", {
target: this.element,
detail: { newFrame, ...options },
Expand Down
16 changes: 8 additions & 8 deletions src/core/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ export class Session {
}
}

allowsImmediateRender({ element }, isPreview, options) {
const event = this.notifyApplicationBeforeRender(element, isPreview, options)
allowsImmediateRender({ element }, options) {
const event = this.notifyApplicationBeforeRender(element, options)
const {
defaultPrevented,
detail: { render }
Expand All @@ -312,9 +312,9 @@ export class Session {
return !defaultPrevented
}

viewRenderedSnapshot(_snapshot, isPreview, renderMethod) {
viewRenderedSnapshot(_snapshot, _isPreview, renderMethod) {
this.view.lastRenderedLocation = this.history.location
this.notifyApplicationAfterRender(isPreview, renderMethod)
this.notifyApplicationAfterRender(renderMethod)
}

preloadOnLoadLinksForView(element) {
Expand Down Expand Up @@ -370,15 +370,15 @@ export class Session {
return dispatch("turbo:before-cache")
}

notifyApplicationBeforeRender(newBody, isPreview, options) {
notifyApplicationBeforeRender(newBody, options) {
return dispatch("turbo:before-render", {
detail: { newBody, isPreview, ...options },
detail: { newBody, ...options },
cancelable: true
})
}

notifyApplicationAfterRender(isPreview, renderMethod) {
return dispatch("turbo:render", { detail: { isPreview, renderMethod } })
notifyApplicationAfterRender(renderMethod) {
return dispatch("turbo:render", { detail: { renderMethod } })
}

notifyApplicationAfterPageLoad(timing = {}) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class View {

const renderInterception = new Promise((resolve) => (this.#resolveInterceptionPromise = resolve))
const options = { resume: this.#resolveInterceptionPromise, render: this.renderer.renderElement }
const immediateRender = this.delegate.allowsImmediateRender(snapshot, isPreview, options)
const immediateRender = this.delegate.allowsImmediateRender(snapshot, options)
if (!immediateRender) await renderInterception

await this.renderSnapshot(renderer)
Expand Down
10 changes: 0 additions & 10 deletions src/tests/functional/rendering_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ test("triggers before-render and render events", async ({ page }) => {
assert.equal(await newBody, await page.evaluate(() => document.body.outerHTML))
})

test("includes isPreview in render event details", async ({ page }) => {
await page.click("#same-origin-link")

const { isPreview } = await nextEventNamed(page, "turbo:before-render")
assert.equal(isPreview, false)

await nextEventNamed(page, "turbo:render")
assert.equal(await isPreview, false)
})

test("triggers before-render, render, and load events for error pages", async ({ page }) => {
await page.click("#nonexistent-link")
const { newBody } = await nextEventNamed(page, "turbo:before-render")
Expand Down

0 comments on commit 3ce4849

Please sign in to comment.