Skip to content

Commit

Permalink
Replace remaining calls to nextAnimationFrame by nextRepaint (hotwire…
Browse files Browse the repository at this point in the history
…d#1102)

This ensures that page refreshes work properly when the page is in the background.
  • Loading branch information
brunoprietog authored and domchristie committed Jul 15, 2024
1 parent e58ad78 commit a546531
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
6 changes: 2 additions & 4 deletions src/core/drive/visit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FetchMethod, FetchRequest } from "../../http/fetch_request"
import { getAnchor } from "../url"
import { PageSnapshot } from "./page_snapshot"
import { getHistoryMethodForAction, uuid } from "../../util"
import { getHistoryMethodForAction, uuid, nextRepaint } from "../../util"
import { StreamMessage } from "../streams/stream_message"
import { ViewTransitioner } from "./view_transitioner"

Expand Down Expand Up @@ -418,9 +418,7 @@ export class Visit {

async render(callback) {
this.cancelRender()
await new Promise((resolve) => {
this.frame = requestAnimationFrame(() => resolve())
})
this.frame = await nextRepaint()
await callback()
delete this.frame
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/frames/frame_renderer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { activateScriptElement, nextAnimationFrame } from "../../util"
import { activateScriptElement, nextRepaint } from "../../util"
import { Renderer } from "../renderer"

export class FrameRenderer extends Renderer {
Expand All @@ -25,14 +25,14 @@ export class FrameRenderer extends Renderer {
}

async render() {
await nextAnimationFrame()
await nextRepaint()
this.preservingPermanentElements(() => {
this.loadFrameElement()
})
this.scrollFrameIntoView()
await nextAnimationFrame()
await nextRepaint()
this.focusFirstAutofocusableElement()
await nextAnimationFrame()
await nextRepaint()
this.activateScriptElements()
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/streams/stream_message_renderer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Bardo } from "../bardo"
import { getPermanentElementById, queryPermanentElementsAll } from "../snapshot"
import { around, elementIsFocusable, nextAnimationFrame, queryAutofocusableElement, uuid } from "../../util"
import { around, elementIsFocusable, nextRepaint, queryAutofocusableElement, uuid } from "../../util"

export class StreamMessageRenderer {
render({ fragment }) {
Expand Down Expand Up @@ -57,7 +57,7 @@ async function withAutofocusFromFragment(fragment, callback) {
}

callback()
await nextAnimationFrame()
await nextRepaint()

const hasNoActiveElement = document.activeElement == null || document.activeElement == document.body

Expand Down

0 comments on commit a546531

Please sign in to comment.