Skip to content

Support optional timeout for idle deferred triggers#67190

Merged
thePunderWoman merged 3 commits intoangular:mainfrom
SkyZeroZx:feature/add-on-idle-options
Mar 4, 2026
Merged

Support optional timeout for idle deferred triggers#67190
thePunderWoman merged 3 commits intoangular:mainfrom
SkyZeroZx:feature/add-on-idle-options

Conversation

@SkyZeroZx
Copy link
Contributor

@SkyZeroZx SkyZeroZx commented Feb 21, 2026

This change allows supply a timeout value in the on idle trigger of an Angular @defer block, which translates into passing the timeout option to requestIdleCallback.

That way, if the browser doesn’t schedule the callback soon enough, the work will run no later than the specified timeout in options

Closes #67187

Usage

@defer (on idle(500)) {
 <heavy-component />
}

@defer (prefetch on idle(500)) {
 <heavy-component />
}

@defer (hydrate on idle(500)) {
 <heavy-component />
}

Other information

  • Add option-based buckets in IdleScheduler to group callbacks and avoid redundant idle scheduling
  • Add IdleRequestOptions support to IdleService
  • Add language service support to detect the new @defer idle(300) syntax

@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: core Issues related to the framework runtime labels Feb 21, 2026
@ngbot ngbot bot added this to the Backlog milestone Feb 21, 2026
@thePunderWoman
Copy link
Contributor

@SkyZeroZx requestIdleCallback's options currently only have timeout. Let's just do idle(500) rather than the object notation. It's less characters, and in the case that some future unlocks other options for idle, we can do a migration pretty easily on that.

@SkyZeroZx
Copy link
Contributor Author

@SkyZeroZx requestIdleCallback's options currently only have timeout. Let's just do idle(500) rather than the object notation. It's less characters, and in the case that some future unlocks other options for idle, we can do a migration pretty easily on that.

Good point, we can create a migration if that happens, then I'll continue with idle(500). I'm updating soon

@SkyZeroZx SkyZeroZx force-pushed the feature/add-on-idle-options branch 3 times, most recently from fa1fa0c to deeca94 Compare February 25, 2026 16:26
@angular-robot angular-robot bot added the area: language-service Issues related to Angular's VS Code language service label Feb 25, 2026
@SkyZeroZx SkyZeroZx force-pushed the feature/add-on-idle-options branch from deeca94 to 3ac06c9 Compare February 25, 2026 17:20
@SkyZeroZx SkyZeroZx changed the title WIP feat(core): Support optional timeout for idle deferred triggers Support optional timeout for idle deferred triggers Feb 25, 2026
@SkyZeroZx SkyZeroZx marked this pull request as ready for review February 25, 2026 17:41
@pullapprove pullapprove bot requested a review from atscott February 25, 2026 17:41
IdleService now accepts IdleRequestOptions,
enabling configuration of requestIdleCallback behavior in compatible environments.
Allows specifying a timeout parameter for idle-based deferred triggers, enabling more granular control over when deferred actions are executed.

Closes angular#67187
Extends language service parsing and validation to support `@defer on idle(300)`
@SkyZeroZx SkyZeroZx force-pushed the feature/add-on-idle-options branch from 3ac06c9 to 5b34da7 Compare March 3, 2026 17:26
@thePunderWoman thePunderWoman requested review from thePunderWoman and removed request for atscott March 3, 2026 18:10
@thePunderWoman
Copy link
Contributor

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for an optional timeout for idle deferred triggers, a valuable feature for controlling when deferred content loads. The implementation is well-structured, involving a significant refactoring of IdleScheduler to use option-based buckets, which is key for handling different requestIdleCallback options. The related services, compiler instructions, and language service have been updated accordingly. The changes are well-tested with new unit, integration, and golden file tests. I have one suggestion to improve code clarity in the IdleScheduler.

Copy link
Contributor

@thePunderWoman thePunderWoman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Thanks for waiting on idle for my review.

reviewed-for: fw-compiler, fw-general, public-api

@pullapprove pullapprove bot requested review from atscott and devversion March 3, 2026 22:12
@thePunderWoman thePunderWoman added target: major This PR is targeted for the next major release action: merge The PR is ready for merge by the caretaker labels Mar 3, 2026
@thePunderWoman thePunderWoman merged commit c6f98c7 into angular:main Mar 4, 2026
22 checks passed
@thePunderWoman
Copy link
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime area: language-service Issues related to Angular's VS Code language service detected: feature PR contains a feature commit target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

On idle trigger does not support providing an IdleDeadline

2 participants