Skip to content

Commit 8b0004a

Browse files
committed
fix(command-flow): support scheduler SSR
1 parent 795cdfc commit 8b0004a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

packages/command-flow/src/scheduler.ts

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { forwardRef, Injectable } from '@angular/core';
1+
import {
2+
ExperimentalPendingTasks,
3+
forwardRef,
4+
inject,
5+
Injectable,
6+
} from '@angular/core';
27

38
@Injectable({
49
providedIn: 'root',
@@ -11,18 +16,26 @@ export abstract class CommandFlowScheduler {
1116
/**
1217
* Implementation of {@link CommandFlowScheduler} that uses
1318
* `setImmediate` to schedule the next execution.
19+
* The scheduled function is added to {@link PendingTask} for SSR support.
1420
*/
1521
@Injectable({ providedIn: 'root' })
1622
export class SetTimeoutCommandFlowScheduler implements CommandFlowScheduler {
23+
#tasks = inject(ExperimentalPendingTasks);
24+
1725
next(fn: () => void): void {
18-
setTimeout(fn);
26+
const done = this.#tasks.add();
27+
setTimeout(() => {
28+
fn();
29+
done();
30+
});
1931
}
2032
}
2133

2234
/**
2335
* Implementation of {@link CommandFlowScheduler} that uses
2436
* `requestAnimationFrame` to schedule the next execution.
2537
* Available only in the browser platform.
38+
* @deprecated prefer {@link SetTimeoutCommandFlowScheduler} for better compatibility.
2639
*/
2740
@Injectable({ providedIn: 'root' })
2841
export class AnimationFrameCommandFlowScheduler

0 commit comments

Comments
 (0)