Title: Creating a view inside an `effect` will track any signal reads that happen in the view · Issue #54548 · angular/angular · GitHub
Open Graph Title: Creating a view inside an `effect` will track any signal reads that happen in the view · Issue #54548 · angular/angular
X Title: Creating a view inside an `effect` will track any signal reads that happen in the view · Issue #54548 · angular/angular
Description: Which @angular/* package(s) are the source of the bug? Don't known / other Is this a regression? No Description I have a PopoverDirective which contains an input that allows the developer to pass in a custom template. It works like this:...
Open Graph Description: Which @angular/* package(s) are the source of the bug? Don't known / other Is this a regression? No Description I have a PopoverDirective which contains an input that allows the developer to pass i...
X Description: Which @angular/* package(s) are the source of the bug? Don't known / other Is this a regression? No Description I have a PopoverDirective which contains an input that allows the developer to pa...
Opengraph URL: https://github.com/angular/angular/issues/54548
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Creating a view inside an `effect` will track any signal reads that happen in the view","articleBody":"### Which @angular/* package(s) are the source of the bug?\r\n\r\nDon't known / other\r\n\r\n### Is this a regression?\r\n\r\nNo\r\n\r\n### Description\r\n\r\nI have a `PopoverDirective` which contains an input that allows the developer to pass in a custom template. It works like this:\r\n```ts\r\n\u003cdiv\r\n appPopover\r\n [isPopoverVisible]=\"isPopoverVisible()\"\r\n [popoverTemplate]=\"popoverTemplate\"\r\n>\r\n Regular content here\r\n\u003c/div>\r\n\r\n\u003cng-template #popoverTemplate> Popover content here \u003c/ng-template>\r\n```\r\n\r\nInternally, this directive fill open or destroy the popover depending on the `isPopoverVisible` input:\r\n```ts\r\neffect(() => {\r\n if (this.isPopoverVisible()) {\r\n this.openPopover();\r\n } else {\r\n this.destroyPopover();\r\n }\r\n});\r\n```\r\n\r\nThis works welll, but when adding signals into the `popoverTemplate` I notice that any effects contained inside the `appPopover` directive will fire again. Even if none of the directive's inputs have changed.\r\n\r\nFor example:\r\n\r\n```ts\r\n\u003cdiv\r\n appPopover\r\n [isPopoverVisible]=\"isPopoverVisible()\"\r\n [popoverTemplate]=\"popoverTemplate\"\r\n>\r\n Regular content here\r\n\u003c/div>\r\n\r\n\u003cng-template #popoverTemplate> {{ someSignal() }} \u003c/ng-template>\r\n```\r\n\r\nWhen `someSignal` changes, my effect inside the `appPopover` directive will now fire _again_, even though none of its inputs have changed (only the input of the template we pass in has changed).\r\n\r\nThis feels unintentional, I'd like to know if this is intended behaviour, or a bug in the framework.\r\n\r\n### Please provide a link to a minimal reproduction of the bug\r\n\r\nhttps://github.com/kfrancois/angular-effects-repro\r\n\r\nAlso available in Stackblitz: https://stackblitz.com/github/kfrancois/angular-effects-repro\r\n\r\n### Please provide the exception or error you saw\r\n\r\nUsing the above link, follow these steps:\r\n\r\n1. Open the console\r\n2. Click on the `Show popover` button\r\n3. Click on the `Do async logic to populate popover template` button\r\n4. Observe the console output\r\n\r\nOn the \"working\" example, `isPopoverVisible: true` does not log twice.\r\nOn the \"broken\" example, `isPopoverVisible: true` does log twice, which is unexpected.\r\n\r\n### Please provide the environment you discovered this bug in (run `ng version`)\r\n\r\n```true\r\nAngular CLI: 17.2.0\r\nNode: 21.6.1 (Unsupported)\r\nPackage Manager: npm 10.4.0\r\nOS: darwin arm64\r\n\r\nAngular: 17.2.1\r\n```\r\n\r\n\r\n### Anything else?\r\n\r\n_No response_","author":{"url":"https://github.com/kfrancois","@type":"Person","name":"kfrancois"},"datePublished":"2024-02-21T16:54:09Z","url":"https://github.com/angular/angular/issues/54548"}
| 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:816097c4-2bb0-6cba-e750-7724e4500509 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B83E:2A5566:1753529:1E9B1B7:6B01FEEC |
| html-safe-nonce | 9699f28e8c5a22b32857446ec8836eb2dc11ad4c69631abae679ca756087b6f3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODNFOjJBNTU2NjoxNzUzNTI5OjFFOUIxQjc6NkIwMUZFRUMiLCJ2aXNpdG9yX2lkIjoiMzI4MTAwNzE2NjUzNzk4OTg2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6c786dea6b707a19c5bf848d580051f97bc9de59c347ff247ddc314d9c6378e7 |
| hovercard-subject-tag | issue:2147239954 |
| 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/54548/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3bc4e6e589418902294e9bcaa60aa9469f1d02c8a4c6c32a5ee89dcf24d064a9/angular/angular/issues/54548 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3bc4e6e589418902294e9bcaa60aa9469f1d02c8a4c6c32a5ee89dcf24d064a9/angular/angular/issues/54548 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? Don't known / other Is this a regression? No Description I have a PopoverDirective which contains an input that allows the developer to pass i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kfrancois |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width