Comments (7)
This happens because the IntersectionObserver
used to implement the on viewport
trigger is asynchronous, so each level introduces its own microtick delay and therefore an additional round of change detection.
The documentation also states that the on viewport
trigger is driven by IntersectionObserver
, confirming its asynchronous behavior, so this isn't a bug per se. That said, I can see how a "preflight" viewport test might help avoid the additional microtick latency and its associated change detection cycle.
from angular.
Even that isn't great really, as it would result in a forced layout.
from angular.
I reopen the issue because I need some clarification from angular team.
Is it ok to execute template expressions O(n^2) times in the case of defered recursive template?
from angular.
I'm going to close this as working-as-intended.
In general, using @defer
recursively this way will do N change detections as it's truly a waterfall of rendering:
- A
@defer
block is rendered and creates the placeholder element in the first change detection. IntersectionObserver
asynchronously observes the placeholder in the layout and fires an event.- That event triggers the
@defer
block, and the next round of change detection runs, creating the next@defer
block (goto 1)
It's not feasible for Angular to synchronously evaluate the on viewport
condition as that would require reflowing the page in the middle of rendering, which could have a significantly negative performance impact on the rest of the application.
Each template expression will be executed O(N) times - once for each step in the waterfall.
You observe your logging statement being called O(N^2) times because each instance of the template has its own logging binding, so you end up with N instances * O(N) calls per instance.
from angular.
In general, using @defer recursively this way will do N change detections as it's truly a waterfall of rendering
@alxhub May I conclude that using recursive template is anti-pattern in angular?
from angular.
Recursive templates aren't really related to this issue. They don't by themselves cause waterfalls, and it's easy to rewrite the example into a waterfall without recursive templates at all.
from angular.
@alxhub now I see, the problem is we can't render all ng-template
embedded views in one changes detection round because IntersectionObserver
triggers that, other rounds. But if use recursive ng-template
without @defer
angular renders it with help of only one changes detection round.
Unfortunately we can't prevent execution of template expressions previously created (by IntersectionObserver's
changes detection rounds) embedded views because there is no way to control changes detection strategy per embedded view.
As I know, signals will be able to mark view for check and we will be able to avoid situation like above. Is that related to embedded view also or it is related only to component level view?
from angular.
Related Issues (20)
- foo = signal(''): if string is empty, !!foo () returns false HOT 1
- Form input mask provided by the framework HOT 6
- [Feature] Introduce Type-safe Token Providing HOT 7
- docs: `inject()` is missing all overloads HOT 2
- Add distinction between model() and model.required() on type level HOT 1
- Standalone Component Exports HOT 1
- Set ViewEncapsulation per module HOT 2
- setting signal outside of angular zone error HOT 3
- View provider/provider info that's logged in the console is incorrect
- No more subclasses or `implements`/`extends` information in API doc
- Missing code blocks in usage notes. HOT 1
- toSignal does not change if new published value passes equality check and there is no way to modify that HOT 2
- ErrorNG8001 ${element} is not know element HOT 11
- FormGroup.reset() input typings are incorrect HOT 2
- ErrorHandler docs don't have standalone alternative HOT 2
- Allow one time binding input HOT 1
- Missing example code for accessibility best practices case study HOT 1
- PromiseRejectionEvent not fired
- feat(signal_effect with explicit deps): introduce a new "watch" func having explicit signal_deps and skipFirstCallback HOT 4
- Generate Error routes at build time.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular.