Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support some of the triggers from @defer for the @if block #53452

Closed
rosostolato opened this issue Dec 8, 2023 · 4 comments
Closed

Support some of the triggers from @defer for the @if block #53452

rosostolato opened this issue Dec 8, 2023 · 4 comments
Assignees
Labels
area: core Issues related to the framework runtime core: control flow Issues related to the built-in control flow (@if, @for, @switch)
Milestone

Comments

@rosostolato
Copy link

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

Maybe not all defer triggers make sense for the if block, but some of them yes. For example the on viewport trigger, you could only render a component once it enters the viewport. That's perfect for a virtual scroller implementation.

Proposed solution

@for (item of items; track item.id) {
  <div #container [style.height.px]="500">
    @if (on viewport(container)) {
      <app-heavy-component [item]="item" />
    }
  </div>
}

Alternatives considered

If it's not possible to bring those triggers to the if block, at least we could add another section to defer just like prefetch to let you destroy the component.

@for (item of items; track item.id) {
  <div #container [style.height.px]="500">
    @defer (on viewport(container); destroy on viewport(container)) {
      <app-heavy-component [item]="item" />
    }
  </div>
}

It could be:
destroy on exitViewport(container)
destroy on exit(container)

Or anything else that makes sense.

@jessicajaniuk
Copy link
Contributor

This isn't a 100% duplicate, but it's essentially the same as #53185. It's likely we wouldn't support these blocks directly on @if and @for, but we are considering other abstractions that would solve for this case.

@jessicajaniuk jessicajaniuk added area: core Issues related to the framework runtime core: control flow Issues related to the built-in control flow (@if, @for, @switch) labels Dec 8, 2023
@ngbot ngbot bot added this to the needsTriage milestone Dec 8, 2023
@pkozlowski-opensource
Copy link
Member

Agree with @jessicajaniuk - I don't think it is reasonable to embed many of the possible show / hide conditions directly in the control flow. We should rather expose a service / directive / signal that flips data model depending on a given element being in the viewport or not.

@pkozlowski-opensource pkozlowski-opensource self-assigned this Dec 13, 2023
@pkozlowski-opensource
Copy link
Member

Closing based on the above reasoning.

@pkozlowski-opensource pkozlowski-opensource closed this as not planned Won't fix, can't repro, duplicate, stale Mar 7, 2024
@angular-automatic-lock-bot
Copy link

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 Apr 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime core: control flow Issues related to the built-in control flow (@if, @for, @switch)
Projects
None yet
Development

No branches or pull requests

3 participants