Title: elements: too many change detection runs during initialization · Issue #33059 · angular/angular · GitHub
Open Graph Title: elements: too many change detection runs during initialization · Issue #33059 · angular/angular
X Title: elements: too many change detection runs during initialization · Issue #33059 · angular/angular
Description: 🐞 bug report Affected Package The issue is caused by package @angular/elements. Is this a regression? No. Description During custom element initialization (i.e. initializeComponent()), the default NgElementStrategy, ComponentNgElementStr...
Open Graph Description: 🐞 bug report Affected Package The issue is caused by package @angular/elements. Is this a regression? No. Description During custom element initialization (i.e. initializeComponent()), the default ...
X Description: 🐞 bug report Affected Package The issue is caused by package @angular/elements. Is this a regression? No. Description During custom element initialization (i.e. initializeComponent()), the default ...
Opengraph URL: https://github.com/angular/angular/issues/33059
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"elements: too many change detection runs during initialization","articleBody":"# 🐞 bug report\r\n\r\n### Affected Package\r\n\r\nThe issue is caused by package @angular/elements.\r\n\r\n\r\n### Is this a regression?\r\n\r\nNo.\r\n\r\n\r\n### Description\r\n\r\nDuring custom element initialization (i.e. [initializeComponent()][1]), the default `NgElementStrategy`, [ComponentNgElementStrategy][2], (transitively) may call [setInputValue()][3], which in turn calls [scheduleDetectChanges()][4]. Right after, `initializeComponent()` calls [detectChanges()][5].\r\n\r\nHowever, despite CD being run synchronously after `setInputValue()`, the scheduled, asynchronous CD (scheduled inside `setInputValue()`) will still run.\r\n\r\nThis results in two CDs per Angular custom element instance, which can negatively affect initial page loads or route transitions for pages/routes with many custom elements. (This is the case for example in https://angular.io/guide/router, which has ~200 custom elements.)\r\n\r\n**Possible solution:**\r\nI think it would be reasonable to cancel scheduled CD, if CD is triggered earlier than scheduled.\r\n\r\n(See the reproduction below for a demo of the fix.)\r\n\r\n\r\n### 🔬 Minimal Reproduction\r\n\r\nhttps://stackblitz.com/edit/ngelements-issue-33059?file=src/app/app.component.ts\r\n\r\n\r\n### Anything else relevant?\r\n\r\nRelated issues: #23813, #33060\r\n\r\n\r\n[1]: https://github.com/angular/angular/blob/9f0c549bc/packages/elements/src/component-factory-strategy.ts#L146-L162\r\n[2]: https://github.com/angular/angular/blob/9f0c549bc/packages/elements/src/component-factory-strategy.ts#L45\r\n[3]: https://github.com/angular/angular/blob/9f0c549bc/packages/elements/src/component-factory-strategy.ts#L168\r\n[4]: https://github.com/angular/angular/blob/9f0c549bc/packages/elements/src/component-factory-strategy.ts#L139\r\n[5]: https://github.com/angular/angular/blob/9f0c549bc/packages/elements/src/component-factory-strategy.ts#L158\r\n","author":{"url":"https://github.com/gkalpak","@type":"Person","name":"gkalpak"},"datePublished":"2019-10-09T15:30:08Z","url":"https://github.com/angular/angular/issues/33059"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:bb457dfe-7675-610a-25c6-447471bc5953 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AC74:14ECB:16DAEC4:1D029C6:6B0137BB |
| html-safe-nonce | cafe74d5d6f2fa5f3252eff4f21f4a06ae2b23b18df1215f5a5ce64a13ff320e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzc0OjE0RUNCOjE2REFFQzQ6MUQwMjlDNjo2QjAxMzdCQiIsInZpc2l0b3JfaWQiOiI0NTg3ODc2Nzc0NTI3OTczMzA3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 384b587dfc1acd42d6c348b601ea60f505c8f847918b9d767d484d76977a9d81 |
| hovercard-subject-tag | issue:504728208 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/33059/issue_layout |
| twitter:image | https://opengraph.githubassets.com/605d80ab0a9eaca4bd8dfa594fac55979efe429e9537d9a12105fe5a8244d86a/angular/angular/issues/33059 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/605d80ab0a9eaca4bd8dfa594fac55979efe429e9537d9a12105fe5a8244d86a/angular/angular/issues/33059 |
| og:image:alt | 🐞 bug report Affected Package The issue is caused by package @angular/elements. Is this a regression? No. Description During custom element initialization (i.e. initializeComponent()), the default ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gkalpak |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width