Skip to content

Commit

Permalink
options.requestAnimationFrame solves it
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Oct 5, 2024
1 parent 2bc881b commit a1a9bb2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/preact/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ function flushEffects() {

function notifyEffects(this: Effect) {
if (effectsQueue.push(this) === 1) {
(options.debounceRendering || defer)(flushEffects);
(options.requestAnimationFrame || defer)(flushEffects);
}
}

Expand All @@ -394,7 +394,7 @@ function flushComputeds() {

function notifyComputeds(this: Effect) {
if (computedsQueue.push(this) === 1) {
(options.debounceRendering || defer)(flushComputeds);
(options.requestAnimationFrame || defer)(flushComputeds);
}
}

Expand Down
14 changes: 1 addition & 13 deletions packages/preact/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,8 @@ import { useContext, useRef, useState } from "preact/hooks";
import { setupRerender, act } from "preact/test-utils";

const sleep = (ms?: number) => new Promise(r => setTimeout(r, ms));
const defer =
typeof requestAnimationFrame === "undefined"
? setTimeout
: requestAnimationFrame;
const afterFrame = () => {
return new Promise(res => {
defer(res);
});
};

describe.only("@preact/signals", () => {
describe("@preact/signals", () => {
let scratch: HTMLDivElement;
let rerender: () => void;

Expand Down Expand Up @@ -234,7 +225,6 @@ describe.only("@preact/signals", () => {
act(() => {
sig.value = <span>d</span>;
});
await afterFrame();
rerender();
await sleep();

Expand Down Expand Up @@ -707,7 +697,6 @@ describe.only("@preact/signals", () => {
});
expect(scratch.textContent).to.equal("foo");
// expect(spy).not.to.have.been.called;
await afterFrame();
expect(spy).to.have.been.calledOnceWith(
"foo",
scratch.firstElementChild,
Expand Down Expand Up @@ -756,7 +745,6 @@ describe.only("@preact/signals", () => {
render(<App />, scratch);
});

await afterFrame();
expect(cleanup).not.to.have.been.called;
expect(spy).to.have.been.calledOnceWith(
"foo",
Expand Down

0 comments on commit a1a9bb2

Please sign in to comment.