René's URL Explorer Experiment


Title: Template of an OnPush component is no longer updated after a signal change in some cases · Issue #50320 · angular/angular · GitHub

Open Graph Title: Template of an OnPush component is no longer updated after a signal change in some cases · Issue #50320 · angular/angular

X Title: Template of an OnPush component is no longer updated after a signal change in some cases · Issue #50320 · angular/angular

Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description Go to this stackblitz Click on the Toggle state button. item is visible appears Click again on the Toggle state button. item is visible disa...

Open Graph Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description Go to this stackblitz Click on the Toggle state button. item is visible appears Click again on the T...

X Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description Go to this stackblitz Click on the Toggle state button. item is visible appears Click again on the T...

Opengraph URL: https://github.com/angular/angular/issues/50320

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Template of an OnPush component is no longer updated after a signal change in some cases","articleBody":"### Which @angular/* package(s) are the source of the bug?\n\ncore\n\n### Is this a regression?\n\nNo\n\n### Description\n\nGo to [this stackblitz](https://stackblitz.com/edit/angular-nltu6v?file=src/main.ts)\r\nClick on the `Toggle state` button.\r\n`item is visible` appears\r\nClick again on the `Toggle state` button.\r\n`item is visible` disappears\r\nClick again on the `Toggle state` button.\r\nNothing happens! I would expect the `item is visible` element to appear again.\r\n\r\nHere is the code of the stackblitz:\r\n\r\n```ts\r\nimport 'zone.js/dist/zone';\r\nimport {\r\n  ChangeDetectionStrategy,\r\n  Component,\r\n  Directive,\r\n  effect,\r\n  signal,\r\n  Input,\r\n  OnChanges,\r\n  OnDestroy,\r\n  SimpleChanges,\r\n  computed,\r\n} from '@angular/core';\r\nimport { CommonModule } from '@angular/common';\r\nimport { bootstrapApplication } from '@angular/platform-browser';\r\n\r\ninterface State {\r\n  isInDom: boolean;\r\n  shouldBeInDom: boolean;\r\n}\r\n\r\nconst createModel = () => {\r\n  const state = signal\u003cState>({\r\n    isInDom: false,\r\n    shouldBeInDom: false,\r\n  });\r\n  const updateState = (changes: Partial\u003cState>) =>\r\n    state.update((value) => ({\r\n      ...value,\r\n      ...changes,\r\n    }));\r\n  const toggle = () => updateState({ shouldBeInDom: !state().shouldBeInDom });\r\n  const setDomState = (isInDom: boolean) => updateState({ isInDom });\r\n  return { state, toggle, setDomState };\r\n};\r\n\r\n@Directive({\r\n  standalone: true,\r\n  selector: '[myDirective]',\r\n})\r\nexport class MyDirective implements OnChanges, OnDestroy {\r\n  @Input({ required: true })\r\n  myDirective!: ReturnType\u003ctypeof createModel>;\r\n\r\n  async ngOnChanges(changes: SimpleChanges) {\r\n    // Comment the following line to have the issue on display:\r\n    await 0;\r\n    this.myDirective.setDomState(true);\r\n  }\r\n\r\n  async ngOnDestroy() {\r\n    // Uncomment the following line as a work-around to fix the issue:\r\n    // await 0;\r\n    this.myDirective.setDomState(false);\r\n  }\r\n}\r\n\r\n@Component({\r\n  selector: 'my-component',\r\n  standalone: true,\r\n  // Comment the following line as a work-around to fix the issue:\r\n  changeDetection: ChangeDetectionStrategy.OnPush,\r\n  imports: [CommonModule, MyDirective],\r\n  template: `\r\n    \u003cdiv *ngIf=\"state().shouldBeInDom\" [myDirective]=\"model\">item is visible\u003c/div>\r\n  `,\r\n})\r\nexport class MyComponent {\r\n  model = createModel();\r\n  // Uncomment the following line as a work-around to fix the issue:\r\n  // state = this.model.state;\r\n  state = computed(() => this.model.state());\r\n\r\n  constructor() {\r\n    // Uncomment the following line as a work-around to fix the issue:\r\n    // effect(() => console.log(this.state()));\r\n  }\r\n}\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  standalone: true,\r\n  imports: [CommonModule, MyComponent],\r\n  template: `\r\n    \u003cbutton (click)=\"c.model.toggle()\">Toggle state\u003c/button>\r\n    \u003cmy-component #c>\u003c/my-component>\r\n  `,\r\n})\r\nexport class App {}\r\n\r\nbootstrapApplication(App);\r\n```\n\n### Please provide a link to a minimal reproduction of the bug\n\nhttps://stackblitz.com/edit/angular-nltu6v?file=src/main.ts\n\n### Please provide the exception or error you saw\n\n```true\nThere is no exception, no explanation.\n```\n\n\n### Please provide the environment you discovered this bug in (run `ng version`)\n\n```true\nAngular CLI: 16.0.1\r\nNode: 18.16.0\r\nPackage Manager: npm 9.5.1\r\nOS: linux x64\r\n\r\nAngular: 16.0.1\r\n... animations, cli, common, compiler, compiler-cli, core, forms\r\n... platform-browser, platform-browser-dynamic, router\r\n\r\nPackage                         Version\r\n---------------------------------------------------------\r\n@angular-devkit/architect       0.1600.1\r\n@angular-devkit/build-angular   16.0.1\r\n@angular-devkit/core            16.0.1\r\n@angular-devkit/schematics      16.0.1\r\n@schematics/angular             16.0.1\r\nng-packagr                      16.0.1\r\nrxjs                            7.8.1\r\ntypescript                      5.0.4\n```\n\n\n### Anything else?\n\nWhat triggers the bug seems to be the fact that the signal is synchronously changed either from `ngOnChanges` or from `ngOnDestroy` in the directive. If this is done asynchronously, the problem does not happen.\r\n\r\nThis makes me think about the famous `ExpressionChangedAfterItHasBeenCheckedError` issue (even if there is no exception displayed in this case), the idea is the same: there is an issue when updating data at some specific times.\r\n\r\nAs mentioned in the comments of the code, if any of the following modifications is done (alone), the bug does not happen:\r\n- if `state` is a direct reference to `this.model.state` in `MyComponent` instead of being a `computed`\r\n- if an effect that reads `this.state()` is added in the constructor of `MyComponent`\r\n- if `MyComponent` is not `OnPush`\r\n","author":{"url":"https://github.com/divdavem","@type":"Person","name":"divdavem"},"datePublished":"2023-05-16T11:17:31Z","url":"https://github.com/angular/angular/issues/50320"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:f3dff4da-76db-d678-0c3c-882e1ce76a0a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9318:26ECEB:165CA7E:1C8C833:6B01228C
html-safe-nonce52b56759733cd5c9b7d55a6cc53208ff7956d4df28e354617353109460bbe0f8
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MzE4OjI2RUNFQjoxNjVDQTdFOjFDOEM4MzM6NkIwMTIyOEMiLCJ2aXNpdG9yX2lkIjoiNDQ0MTc1MzcxNTAxMTAzNTc4OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacf1c878e7e263a7cc72085eee3f4975edf9b9bc096672b08b94862966a1f1d0ca
hovercard-subject-tagissue:1711809600
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/50320/issue_layout
twitter:imagehttps://opengraph.githubassets.com/7cebd9ae191599261b63b5178beca184ca17f115b00f249894334ab195b6ad07/angular/angular/issues/50320
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/7cebd9ae191599261b63b5178beca184ca17f115b00f249894334ab195b6ad07/angular/angular/issues/50320
og:image:altWhich @angular/* package(s) are the source of the bug? core Is this a regression? No Description Go to this stackblitz Click on the Toggle state button. item is visible appears Click again on the T...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedivdavem
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
go-importgithub.com/angular/angular git https://github.com/angular/angular.git
octolytics-dimension-user_id139426
octolytics-dimension-user_loginangular
octolytics-dimension-repository_id24195339
octolytics-dimension-repository_nwoangular/angular
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id24195339
octolytics-dimension-repository_network_root_nwoangular/angular
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/angular/angular/issues/50320#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F50320
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F50320
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=angular%2Fangular
Reloadhttps://github.com/angular/angular/issues/50320
Reloadhttps://github.com/angular/angular/issues/50320
Reloadhttps://github.com/angular/angular/issues/50320
angularhttps://github.com/angular
angularhttps://github.com/angular/angular
Codehttps://github.com/angular/angular
Issues835 (835)https://github.com/angular/angular/issues
Pull requests141 (141)https://github.com/angular/angular/pulls
Discussionshttps://github.com/angular/angular/discussions
Actionshttps://github.com/angular/angular/actions
Projectshttps://github.com/angular/angular/projects
Security and quality40 (40)https://github.com/angular/angular/security
Insightshttps://github.com/angular/angular/insights
https://github.com/angular/angular
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/50320
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/50320
Template of an OnPush component is no longer updated after a signal change in some caseshttps://github.com/angular/angular/issues/50320#top
https://github.com/pkozlowski-opensource
https://github.com/alxhub
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgenthttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22P3%22
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
bughttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22bug%22
core: reactivityWork related to fine-grained reactivity in the core frameworkhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20reactivity%22
cross-cutting: signalshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22cross-cutting%3A%20signals%22
Backloghttps://github.com/angular/angular/milestone/82
https://github.com/divdavem
divdavemhttps://github.com/divdavem
on May 16, 2023https://github.com/angular/angular/issues/50320#issue-1711809600
this stackblitzhttps://stackblitz.com/edit/angular-nltu6v?file=src/main.ts
https://stackblitz.com/edit/angular-nltu6v?file=src/main.tshttps://stackblitz.com/edit/angular-nltu6v?file=src/main.ts
Nexthttps://github.com/angular/angular/issues/50320?timeline_page=1
https://github.com/pkozlowski-opensource
pkozlowski-opensourcehttps://github.com/pkozlowski-opensource
on May 16, 2023https://github.com/angular/angular/issues/50320#issuecomment-1549980526
pkozlowski-opensourcehttps://github.com/pkozlowski-opensource
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgenthttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22P3%22
bughttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22bug%22
core: reactivityWork related to fine-grained reactivity in the core frameworkhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20reactivity%22
on May 16, 2023https://github.com/angular/angular/issues/50320#event-9260115085
ngbothttps://github.com/apps/ngbot
Backloghttps://github.com/angular/angular/milestone/82
on May 16, 2023https://github.com/angular/angular/issues/50320#event-9260115388
https://github.com/pkozlowski-opensource
pkozlowski-opensourcehttps://github.com/pkozlowski-opensource
on May 16, 2023https://github.com/angular/angular/issues/50320#issuecomment-1550024304
https://stackblitz.com/edit/angular-hu21mk?file=src%2Fmain.tshttps://stackblitz.com/edit/angular-hu21mk?file=src%2Fmain.ts
https://github.com/zip-fa
zip-fahttps://github.com/zip-fa
on May 16, 2023https://github.com/angular/angular/issues/50320#issuecomment-1550222016
https://github.com/divdavem
divdavemhttps://github.com/divdavem
on May 17, 2023https://github.com/angular/angular/issues/50320#issuecomment-1550959562
@pkozlowski-opensourcehttps://github.com/pkozlowski-opensource
your stackblitzhttps://stackblitz.com/edit/angular-hu21mk?file=src%2Fmain.ts
https://github.com/swami-sanapathi
swami-sanapathihttps://github.com/swami-sanapathi
on May 17, 2023https://github.com/angular/angular/issues/50320#issuecomment-1551855557
#49684 (comment)https://github.com/angular/angular/discussions/49684#discussioncomment-5649925
https://github.com/divdavem
divdavemhttps://github.com/divdavem
on Sep 18, 2023https://github.com/angular/angular/issues/50320#issuecomment-1723708536
this stackblitzhttps://stackblitz.com/edit/angular-6uxx7g?file=src%2Fmain.ts
pkozlowski-opensourcehttps://github.com/pkozlowski-opensource
cross-cutting: signalshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22cross-cutting%3A%20signals%22
on Sep 21, 2023https://github.com/angular/angular/issues/50320#event-10438316511
alxhubhttps://github.com/alxhub
completedhttps://github.com/angular/angular/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
58d74a2https://github.com/angular/angular/commit/58d74a29f8476aba2936d058394491fd7e48bf81
on Nov 2, 2023https://github.com/angular/angular/issues/50320#event-10848785189
alxhubhttps://github.com/alxhub
on Nov 2, 2023https://github.com/angular/angular/issues/50320#event-10848785583
refactor(core): Remove warning about signal set during template execu…https://github.com/angular/angular/commit/2ce2ad1c42203b13e004017a4cb278b0253204a0
https://docs.github.com/articles/closing-issues-via-commit-messages
2ce2ad1https://github.com/angular/angular/commit/2ce2ad1c42203b13e004017a4cb278b0253204a0
github-project-automationhttps://github.com/apps/github-project-automation
Reactivityhttps://github.com/orgs/angular/projects/31
on Nov 2, 2023https://github.com/angular/angular/issues/50320
Abseil-bytehttps://github.com/Abseil-byte
on Nov 5, 2023https://github.com/angular/angular/issues/50320#event-10865982467
refactor(core): Remove warning about signal set during template execu…https://github.com/Abseil-byte/angular/commit/f78b64e0213bfba4e826964983218b73b0fef4b1
https://docs.github.com/articles/closing-issues-via-commit-messages
f78b64ehttps://github.com/Abseil-byte/angular/commit/f78b64e0213bfba4e826964983218b73b0fef4b1
divdavemhttps://github.com/divdavem
on Nov 24, 2023https://github.com/angular/angular/issues/50320#event-11055711727
feat: making auUse synchronoushttps://github.com/divdavem/AgnosUI/commit/7fa4ce8a2c67abe7e0bab8a4e0a03f1d2d16da2a
7fa4ce8https://github.com/divdavem/AgnosUI/commit/7fa4ce8a2c67abe7e0bab8a4e0a03f1d2d16da2a
feat: making auUse synchronoushttps://github.com/divdavem/AgnosUI/commit/4617c95f272266ac913f061a770258ba8912e256
4617c95https://github.com/divdavem/AgnosUI/commit/4617c95f272266ac913f061a770258ba8912e256
feat: making auUse synchronoushttps://github.com/divdavem/AgnosUI/commit/badef685f704fccddc5cf374c7f833fb32b87890
badef68https://github.com/divdavem/AgnosUI/commit/badef685f704fccddc5cf374c7f833fb32b87890
https://github.com/apps/angular-automatic-lock-bot
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Dec 3, 2023https://github.com/angular/angular/issues/50320#issuecomment-1837287233
automatic conversation locking policyhttps://github.com/angular/angular/blob/8f24bc9443b3872fe095d9f7f77b308a361a13b4/docs/GITHUB_PROCESS.md#conversation-locking
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Dec 3, 2023https://github.com/angular/angular/issues/50320#event-11130057243
ChellappanRajanhttps://github.com/ChellappanRajan
on Jan 23, 2024https://github.com/angular/angular/issues/50320#event-11564106364
refactor(core): Remove warning about signal set during template execu…https://github.com/ChellappanRajan/angular/commit/ea35beb909d54c7d7e764d17c6ef22cf066d3470
https://docs.github.com/articles/closing-issues-via-commit-messages
ea35bebhttps://github.com/ChellappanRajan/angular/commit/ea35beb909d54c7d7e764d17c6ef22cf066d3470
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular/issues/50320
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular/issues/50320
alxhubhttps://github.com/alxhub
pkozlowski-opensourcehttps://github.com/pkozlowski-opensource
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgenthttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22P3%22
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
bughttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22bug%22
core: reactivityWork related to fine-grained reactivity in the core frameworkhttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22core%3A%20reactivity%22
cross-cutting: signalshttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22cross-cutting%3A%20signals%22
Reactivityhttps://github.com/orgs/angular/projects/31
BacklogNo due datehttps://github.com/angular/angular/milestone/82
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.