mirror of
https://github.com/discourse/discourse.git
synced 2024-11-21 08:34:17 -06:00
DEV: Allow afterFramePaint to be used in tests (#27226)
We need to register a waiter so that `settled()` will wait for `runAfterFramePaint()` callbacks to be run before proceeding.
This commit is contained in:
parent
30e963be03
commit
63b7b598cb
@ -1,8 +1,13 @@
|
||||
import { registerWaiter } from "@ember/test";
|
||||
|
||||
/**
|
||||
* Runs `callback` shortly after the next browser Frame is produced.
|
||||
* ref: https://webperf.tips/tip/measuring-paint-time
|
||||
*/
|
||||
export default function runAfterFramePaint(callback) {
|
||||
let done = false;
|
||||
registerWaiter(() => done);
|
||||
|
||||
// Queue a "before Render Steps" callback via requestAnimationFrame.
|
||||
requestAnimationFrame(() => {
|
||||
// MessageChannel is one of the highest priority task queues
|
||||
@ -10,7 +15,10 @@ export default function runAfterFramePaint(callback) {
|
||||
const messageChannel = new MessageChannel();
|
||||
|
||||
// Setup the callback to run in a Task
|
||||
messageChannel.port1.onmessage = callback;
|
||||
messageChannel.port1.onmessage = () => {
|
||||
done = true;
|
||||
callback();
|
||||
};
|
||||
|
||||
// Queue the Task on the Task Queue
|
||||
messageChannel.port2.postMessage(undefined);
|
||||
|
Loading…
Reference in New Issue
Block a user