Skip to content

feat(core): support IntersectionObserver options in viewport triggers#64130

Closed
crisbeto wants to merge 6 commits intoangular:mainfrom
crisbeto:52799/defer-viewport-params
Closed

feat(core): support IntersectionObserver options in viewport triggers#64130
crisbeto wants to merge 6 commits intoangular:mainfrom
crisbeto:52799/defer-viewport-params

Conversation

@crisbeto
Copy link
Copy Markdown
Member

@crisbeto crisbeto commented Sep 29, 2025

Adds support for customizing the IntersectionObserver options for the on viewport, prefetch on viewport and hydrate on viewport triggers.

Note that the options need to be a static object literal, e.g. @defer (on viewport({trigger, rootMargin: '123px'}).

Fixes #52799.

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: minor This PR is targeted for the next minor release labels Sep 29, 2025
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime labels Sep 29, 2025
@ngbot ngbot bot added this to the Backlog milestone Sep 29, 2025
@crisbeto crisbeto force-pushed the 52799/defer-viewport-params branch from b7057e9 to 8546617 Compare September 29, 2025 12:00
@crisbeto crisbeto marked this pull request as ready for review September 29, 2025 12:37
@pullapprove pullapprove bot requested a review from csmick September 29, 2025 12:37
@pullapprove pullapprove bot added the requires: TGP This PR requires a passing TGP before merging is allowed label Sep 29, 2025
@SkyZeroZx
Copy link
Copy Markdown
Contributor

Is there any particular reason why the IntersectionObserver options must be a static object literal and cannot be dynamic, for example by using signals to customize them at runtime?

@crisbeto
Copy link
Copy Markdown
Member Author

It's because the IntersectionObserver is instantiated during creation mode which is before change detection runs. We could move it to update mode, but I suspect that it won't be worth the added complexity.

…ters

Currently we produce the string value of a defer `on` trigger by concatenating the string values of all of its tokens. This ends up ignoring whitespaces which in turn throws off source spans.

These changes switch to producing the string by taking the text between the start and end tokens, as well as tracking the start index.
Updates the template parser and AST to capture a second object literal parameter on `viewport` triggers.
Updates the template type checker to check the options of the `viewport` trigger against `IntersectionObserver`.
Updates the template pipeline to support options for the `viewport` triggers.
@crisbeto crisbeto force-pushed the 52799/defer-viewport-params branch from 8546617 to 9804ce7 Compare October 3, 2025 11:59
@angular-robot angular-robot bot added the area: docs Related to the documentation label Oct 3, 2025
expect(diags.length).toBe(1);
expect(diags[0].messageText).toBe(
'Trigger with no parameters can only be placed on an @defer that has a @placeholder block',
'Trigger with no target can only be placed on an @defer that has a @placeholder block',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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

Just a couple of small comments.

Adds support for customizing the `IntersectionObserver` options for the `on viewport`, `prefetch on viewport` and `hydrate on viewport` triggers.

Note that the options need to be a static object literal, e.g. `@defer (on viewport(trigger, {rootMargin: '123px'})`.

Fixes angular#52799.
Updates the docs to mention the new options for the `viewport` trigger.
@crisbeto crisbeto force-pushed the 52799/defer-viewport-params branch from b88d4b0 to 3ce33ed Compare October 3, 2025 16:56
@crisbeto
Copy link
Copy Markdown
Member Author

crisbeto commented Oct 3, 2025

Passing TGP

Copy link
Copy Markdown
Contributor

@mturco mturco left a comment

Choose a reason for hiding this comment

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

LGTM

Reviewed-for: primitives-shared

@crisbeto crisbeto removed the request for review from csmick October 6, 2025 14:47
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer requires: TGP This PR requires a passing TGP before merging is allowed labels Oct 6, 2025
@pullapprove pullapprove bot added the requires: TGP This PR requires a passing TGP before merging is allowed label Oct 7, 2025
@crisbeto
Copy link
Copy Markdown
Member Author

crisbeto commented Oct 7, 2025

@AndrewKushnir
Copy link
Copy Markdown
Contributor

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

AndrewKushnir pushed a commit that referenced this pull request Oct 9, 2025
)

Updates the template parser and AST to capture a second object literal parameter on `viewport` triggers.

PR Close #64130
AndrewKushnir pushed a commit that referenced this pull request Oct 9, 2025
Updates the template type checker to check the options of the `viewport` trigger against `IntersectionObserver`.

PR Close #64130
AndrewKushnir pushed a commit that referenced this pull request Oct 9, 2025
)

Updates the template pipeline to support options for the `viewport` triggers.

PR Close #64130
AndrewKushnir pushed a commit that referenced this pull request Oct 9, 2025
…#64130)

Adds support for customizing the `IntersectionObserver` options for the `on viewport`, `prefetch on viewport` and `hydrate on viewport` triggers.

Note that the options need to be a static object literal, e.g. `@defer (on viewport(trigger, {rootMargin: '123px'})`.

Fixes #52799.

PR Close #64130
AndrewKushnir pushed a commit that referenced this pull request Oct 9, 2025
Updates the docs to mention the new options for the `viewport` trigger.

PR Close #64130
@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime area: docs Related to the documentation detected: feature PR contains a feature commit requires: TGP This PR requires a passing TGP before merging is allowed target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@defer additional support for "offset" option for both "on viewport" and "prefetch on viewport"

5 participants