Skip to content

Commit 5513edb

Browse files
Only snapshot frame visits that have actions
Frames that use `data-turbo-action` to promote their navigations to page visits require cache snapshots to be taken prior to them loading, in order for those snapshots to be accurate. However snapshots can be expensive to create for complex pages. In cases where a frame is *not* being promoted, we can avoid taking that snapshot. This helps with some performance issues observed when using frames on very large pages.
1 parent ab4b184 commit 5513edb

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/core/frames/frame_controller.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export class FrameController
6464
readonly restorationIdentifier: string
6565
private previousFrameElement?: FrameElement
6666
private currentNavigationElement?: Element
67-
pageSnapshot?: PageSnapshot
6867

6968
constructor(element: FrameElement) {
7069
this.element = element
@@ -199,7 +198,6 @@ export class FrameController
199198
// Appearance observer delegate
200199

201200
elementAppearedInViewport(element: FrameElement) {
202-
this.pageSnapshot = PageSnapshot.fromElement(element).clone()
203201
this.proposeVisitIfNavigatedWithAction(element, element)
204202
this.loadSourceURL()
205203
}
@@ -369,7 +367,6 @@ export class FrameController
369367

370368
private navigateFrame(element: Element, url: string, submitter?: HTMLElement) {
371369
const frame = this.findFrameElement(element, submitter)
372-
this.pageSnapshot = PageSnapshot.fromElement(frame).clone()
373370

374371
frame.delegate.proposeVisitIfNavigatedWithAction(frame, element, submitter)
375372

@@ -382,6 +379,7 @@ export class FrameController
382379
this.action = getVisitAction(submitter, element, frame)
383380

384381
if (this.action) {
382+
const pageSnapshot = PageSnapshot.fromElement(frame).clone()
385383
const { visitCachedSnapshot } = frame.delegate
386384

387385
frame.delegate.fetchResponseLoaded = (fetchResponse: FetchResponse) => {
@@ -395,7 +393,7 @@ export class FrameController
395393
willRender: false,
396394
updateHistory: false,
397395
restorationIdentifier: this.restorationIdentifier,
398-
snapshot: this.pageSnapshot,
396+
snapshot: pageSnapshot,
399397
}
400398

401399
if (this.action) options.action = this.action

0 commit comments

Comments
 (0)