diff --git a/src/core/drive/page_view.js b/src/core/drive/page_view.js index 1bcb04134..58790d900 100644 --- a/src/core/drive/page_view.js +++ b/src/core/drive/page_view.js @@ -19,7 +19,7 @@ export class PageView extends View { const shouldMorphPage = this.isPageRefresh(visit) && this.snapshot.shouldMorphPage const rendererClass = shouldMorphPage ? MorphingPageRenderer : PageRenderer - const renderer = new rendererClass(this.snapshot, snapshot, rendererClass.renderElement, isPreview, willRender) + const renderer = new rendererClass(this.snapshot, snapshot, isPreview, willRender) if (!renderer.shouldRender) { this.forceReloaded = true @@ -32,7 +32,7 @@ export class PageView extends View { renderError(snapshot, visit) { visit?.changeHistory() - const renderer = new ErrorRenderer(this.snapshot, snapshot, ErrorRenderer.renderElement, false) + const renderer = new ErrorRenderer(this.snapshot, snapshot, false) return this.render(renderer) } diff --git a/src/core/frames/frame_controller.js b/src/core/frames/frame_controller.js index f07d58859..963e3190d 100644 --- a/src/core/frames/frame_controller.js +++ b/src/core/frames/frame_controller.js @@ -33,6 +33,7 @@ export class FrameController { #connected = false #hasBeenLoaded = false #ignoredAttributes = new Set() + #shouldMorphFrame = false action = null constructor(element) { @@ -90,13 +91,10 @@ export class FrameController { } sourceURLReloaded() { - if (this.element.shouldReloadWithMorph) { - this.element.addEventListener("turbo:before-frame-render", ({ detail }) => { - detail.render = MorphingFrameRenderer.renderElement - }, { once: true }) - } + const { refresh, src } = this.element + + this.#shouldMorphFrame = src && refresh === "morph" - const { src } = this.element this.element.removeAttribute("complete") this.element.src = null this.element.src = src @@ -139,6 +137,7 @@ export class FrameController { } } } finally { + this.#shouldMorphFrame = false this.fetchResponseLoaded = () => Promise.resolve() } } @@ -304,11 +303,11 @@ export class FrameController { async #loadFrameResponse(fetchResponse, document) { const newFrameElement = await this.extractForeignFrameElement(document.body) + const rendererClass = this.#shouldMorphFrame ? MorphingFrameRenderer : FrameRenderer if (newFrameElement) { const snapshot = new Snapshot(newFrameElement) - const renderer = new FrameRenderer(this, this.view.snapshot, snapshot, FrameRenderer.renderElement, false, false) - + const renderer = new rendererClass(this, this.view.snapshot, snapshot, false, false) if (this.view.renderPromise) await this.view.renderPromise this.changeHistory() diff --git a/src/core/frames/morphing_frame_renderer.js b/src/core/frames/morphing_frame_renderer.js index fe42065d5..4d5ea9c34 100644 --- a/src/core/frames/morphing_frame_renderer.js +++ b/src/core/frames/morphing_frame_renderer.js @@ -11,4 +11,8 @@ export class MorphingFrameRenderer extends FrameRenderer { morphChildren(currentElement, newElement) } + + async preservingPermanentElements(callback) { + return await callback() + } } diff --git a/src/core/renderer.js b/src/core/renderer.js index f0a02f581..8ede76e65 100644 --- a/src/core/renderer.js +++ b/src/core/renderer.js @@ -3,12 +3,16 @@ import { Bardo } from "./bardo" export class Renderer { #activeElement = null - constructor(currentSnapshot, newSnapshot, renderElement, isPreview, willRender = true) { + static renderElement(currentElement, newElement) { + // Abstract method + } + + constructor(currentSnapshot, newSnapshot, isPreview, willRender = true) { this.currentSnapshot = currentSnapshot this.newSnapshot = newSnapshot this.isPreview = isPreview this.willRender = willRender - this.renderElement = renderElement + this.renderElement = this.constructor.renderElement this.promise = new Promise((resolve, reject) => (this.resolvingFunctions = { resolve, reject })) } diff --git a/src/tests/fixtures/frames.html b/src/tests/fixtures/frames.html index e505852de..1749de14b 100644 --- a/src/tests/fixtures/frames.html +++ b/src/tests/fixtures/frames.html @@ -41,6 +41,7 @@