diff --git a/src/core/drive/morphing_page_renderer.js b/src/core/drive/morphing_page_renderer.js index c070c173e..fc4183c29 100644 --- a/src/core/drive/morphing_page_renderer.js +++ b/src/core/drive/morphing_page_renderer.js @@ -1,4 +1,3 @@ -import { FrameElement } from "../../elements/frame_element" import { PageRenderer } from "./page_renderer" import { dispatch } from "../../util" import { morphElements } from "../morphing" @@ -7,12 +6,16 @@ export class MorphingPageRenderer extends PageRenderer { static renderElement(currentElement, newElement) { morphElements(currentElement, newElement, { callbacks: { - beforeNodeMorphed: element => !canRefreshFrame(element) + beforeNodeMorphed: element => { + return !MorphingPageRenderer.shouldRefreshChildFrameWithMorphing(null, element) + } } }) for (const frame of currentElement.querySelectorAll("turbo-frame")) { - if (canRefreshFrame(frame)) frame.reload() + if (MorphingPageRenderer.shouldRefreshChildFrameWithMorphing(null, frame)) { + frame.reload() + } } dispatch("turbo:morph", { detail: { currentElement, newElement } }) @@ -31,10 +34,3 @@ export class MorphingPageRenderer extends PageRenderer { } } -function canRefreshFrame(frame) { - return frame instanceof FrameElement && - frame.src && - frame.refresh === "morph" && - !frame.closest("[data-turbo-permanent]") && - !frame.parentElement.closest("turbo-frame[src][refresh=morph]") -} diff --git a/src/core/frames/morphing_frame_renderer.js b/src/core/frames/morphing_frame_renderer.js index 3ce2ae5af..8af94aead 100644 --- a/src/core/frames/morphing_frame_renderer.js +++ b/src/core/frames/morphing_frame_renderer.js @@ -1,4 +1,3 @@ -import { FrameElement } from "../../elements/frame_element" import { FrameRenderer } from "./frame_renderer" import { morphChildren } from "../morphing" import { dispatch } from "../../util" @@ -12,11 +11,15 @@ export class MorphingFrameRenderer extends FrameRenderer { morphChildren(currentElement, newElement, { callbacks: { - beforeNodeMorphed: element => !canRefreshFrame(element, currentElement) + beforeNodeMorphed: element => { + return !MorphingFrameRenderer.shouldRefreshChildFrameWithMorphing(currentElement, element) + } } }) for (const frame of currentElement.querySelectorAll("turbo-frame")) { - if (canRefreshFrame(frame, currentElement)) frame.reload() + if (MorphingFrameRenderer.shouldRefreshChildFrameWithMorphing(currentElement, frame)) { + frame.reload() + } } } @@ -25,10 +28,3 @@ export class MorphingFrameRenderer extends FrameRenderer { } } -function canRefreshFrame(frame, currentFrame) { - return frame instanceof FrameElement && - frame.src && - frame.refresh === "morph" && - !frame.closest("[data-turbo-permanent]") && - frame.parentElement.closest("turbo-frame[src][refresh=morph]").id === currentFrame.id -} diff --git a/src/core/renderer.js b/src/core/renderer.js index 8ede76e65..97b97682a 100644 --- a/src/core/renderer.js +++ b/src/core/renderer.js @@ -1,3 +1,4 @@ +import { FrameElement } from "../elements/frame_element" import { Bardo } from "./bardo" export class Renderer { @@ -7,6 +8,13 @@ export class Renderer { // Abstract method } + static shouldRefreshChildFrameWithMorphing(parentFrame, frame) { + return frame instanceof FrameElement && + frame.shouldReloadWithMorph && + !frame.closest("[data-turbo-permanent]") && + frame.parentElement.closest("turbo-frame[src][refresh=morph]") === parentFrame + } + constructor(currentSnapshot, newSnapshot, isPreview, willRender = true) { this.currentSnapshot = currentSnapshot this.newSnapshot = newSnapshot