René's URL Explorer Experiment


Title: @SkipSelf() cd: ChangeDetectorRef doesn't return parent ChangeDetector · Issue #39475 · angular/angular · GitHub

Open Graph Title: @SkipSelf() cd: ChangeDetectorRef doesn't return parent ChangeDetector · Issue #39475 · angular/angular

X Title: @SkipSelf() cd: ChangeDetectorRef doesn't return parent ChangeDetector · Issue #39475 · angular/angular

Description: 🐞 bug report Affected Package @angular/core/di Is this a regression? I'm not sure, but given this workaround for bug #22560 it probably worked pre-Ivy. Description It's not possible for a component to obtain the ChangeDetectorRef or Inje...

Open Graph Description: 🐞 bug report Affected Package @angular/core/di Is this a regression? I'm not sure, but given this workaround for bug #22560 it probably worked pre-Ivy. Description It's not possible for a component...

X Description: 🐞 bug report Affected Package @angular/core/di Is this a regression? I'm not sure, but given this workaround for bug #22560 it probably worked pre-Ivy. Description It's not possible for a c...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"@SkipSelf() cd: ChangeDetectorRef doesn't return parent ChangeDetector","articleBody":"# 🐞 bug report\r\n\r\n### Affected Package\r\n@angular/core/di\r\n\r\n### Is this a regression?\r\nI'm not sure, but given [this workaround](https://github.com/angular/angular/issues/22560#issuecomment-473958144) for bug #22560 it probably worked pre-Ivy.\r\n\r\n### Description\r\n\r\nIt's not possible for a component to obtain the `ChangeDetectorRef` or `Injector` from its parent by using @SkipSelf. eg:\r\n\r\n```ts\r\n  constructor(\r\n    // Using parent ChangeDetector, b/c host bindings are part of the parent CD.\r\n    // Not intuitive, but true: https://github.com/angular/angular/issues/22560\r\n    @SkipSelf() changeDetector: ChangeDetectorRef\r\n  ) {\r\n```\r\n\r\nThere is no compile error or runtime error, but the argument passed in is the component's ChangeDetectorRef or Injector.\r\n\r\nThe bug is apparent in `getOrCreateInjectable()`:\r\n```ts\r\nexport function getOrCreateInjectable\u003cT>(\r\n    tNode: TDirectiveHostNode|null, lView: LView, token: Type\u003cT>|InjectionToken\u003cT>,\r\n    flags: InjectFlags = InjectFlags.Default, notFoundValue?: any): T|null {\r\n  if (tNode !== null) {\r\n    const bloomHash = bloomHashBitOrFactory(token);\r\n    // If the ID stored here is a function, this is a special object like ElementRef or TemplateRef\r\n    // so just call the factory function to create it.\r\n    if (typeof bloomHash === 'function') {\r\n      enterDI(lView, tNode);\r\n      try {\r\n        const value = bloomHash();\r\n        if (value == null && !(flags & InjectFlags.Optional)) {\r\n          throw new Error(`No provider for ${stringifyForError(token)}!`);\r\n        } else {\r\n          return value;\r\n        }\r\n      } finally {\r\n        leaveDI();\r\n      }\r\n    } else if (typeof bloomHash == 'number') {\r\n      if (bloomHash === -1) {\r\n        // `-1` is a special value used to identify `Injector` types.\r\n        return new NodeInjector(tNode, lView) as any;\r\n      }\r\n```\r\n\r\nIf the injection token is one of (ChangeDetectorRef, Injector, ElementRef, ViewContainerRef, TemplateRef) it has a `NG_ELEMENT_ID` that is a function, which results in all `InjectFlags` being ignored except `InjectFlags.Optional`.\r\n\r\nIn combination with this bug ( [InjectFlags ignored by NodeInjector.get()](https://github.com/angular/angular/issues/31776#issuecomment-717398208) ) and this by-design bug ( [HostBindings not updated by detectChanges() in OnPush component](https://github.com/angular/angular/issues/22560) ), there's no reasonable way to update HostBindings in OnPush components.\r\n\r\nI think it's reasonable that some of the unsupported injection tokens don't support `@SkipSelf()` (eg TemplateRef and ViewContainerRef make sense; Injector is debatable), but due to HostBindings only being updated by the parent ChangeDetector, we need a straightforward way to obtain the parent ChangeDetector. Also, if `@SkipSelf()` (or other flags) aren't supported, an error should be raised (compile time or runtime) instead of injecting the wrong argument.\r\n\r\n## 🔬 Minimal Reproduction\r\nThis is a karma test running in StackBlitz\r\nhttps://stackblitz.com/edit/ng10-bug-skipself\r\n\r\nTest source:\r\n```ts\r\nimport { ChangeDetectorRef, Component, Injectable, Injector, SkipSelf } from '@angular/core';\r\nimport { ComponentFixture, TestBed } from '@angular/core/testing';\r\n\r\n@Injectable()\r\nclass TestService {\r\n  constructor(public id: string) { }\r\n}\r\n\r\n@Component({\r\n  selector: 'app-child',\r\n  template: `\u003cdiv>nothing to see here\u003c/div>`,\r\n  providers: [\r\n    {\r\n      provide: TestService,\r\n      useFactory: () => new TestService('child')\r\n    }\r\n  ]\r\n})\r\nclass ChildComponent {\r\n\r\n  constructor(\r\n    public changeDetector: ChangeDetectorRef,\r\n    @SkipSelf() public parentChangeDetector: ChangeDetectorRef,\r\n    public injector: Injector,\r\n    @SkipSelf() public parentInjector: Injector,\r\n    @SkipSelf() public testService: TestService\r\n\r\n  ) { }\r\n\r\n}\r\n\r\n@Component({\r\n  selector: 'app-parent',\r\n  template: `\u003capp-child>\u003c/app-child>`,\r\n  providers: [\r\n    {\r\n      provide: TestService,\r\n      useFactory: () => new TestService('parent')\r\n    }\r\n  ]\r\n})\r\nclass ParentComponent {\r\n\r\n  constructor(\r\n    public changeDetector: ChangeDetectorRef,\r\n    public injector: Injector\r\n  ) { }\r\n\r\n}\r\n\r\ndescribe('Component injection with @SkipSelf', () => {\r\n\r\n  let fixture: ComponentFixture\u003cParentComponent>;\r\n  let child: ChildComponent;\r\n\r\n  beforeEach((() => {\r\n    TestBed.configureTestingModule({\r\n      declarations: [\r\n        ChildComponent,\r\n        ParentComponent\r\n      ],\r\n    }).compileComponents();\r\n\r\n    fixture = TestBed.createComponent(ParentComponent);\r\n    child = fixture.debugElement.children[0].componentInstance as ChildComponent;\r\n  }));\r\n\r\n  it('child can get parent Injector (FAILS)', () => {\r\n    expect((child.parentInjector as any)._lView)\r\n      .toBe((fixture.componentInstance.injector as any)._lView);\r\n  });\r\n\r\n  it('child can get parent ChangeDetector (FAILS)', () => {\r\n    expect((child.parentChangeDetector as any)._cdRefInjectingView)\r\n      .toBe((fixture.componentInstance.changeDetector as any)._cdRefInjectingView);\r\n  });\r\n\r\n  it('inject(@SkipSelf Injector) is different from inject(Injector) (FAILS)', () => {\r\n    expect((child.parentInjector as any)._lView)\r\n      .not.toBe((child.injector as any)._lView);\r\n  });\r\n\r\n  it('inject(@SkipSelf Injector) returns service from parent (FAILS)', () => {\r\n    const parentInjectorService = child.parentInjector.get(TestService);\r\n    const childInjectorService = child.injector.get(TestService);\r\n    expect(parentInjectorService.id)\r\n      .not.toBe(childInjectorService.id);\r\n  });\r\n\r\n  it('inject(@SkipSelf ChangeDetectorRef) is different from inject(ChangeDetectorRef) (FAILS)', () => {\r\n    expect((child.parentChangeDetector as any)._cdRefInjectingView)\r\n      .not.toBe((child.changeDetector as any)._cdRefInjectingView);\r\n  });\r\n\r\n  it('inject(@SkipSelf TestService) returns service from parent component (PASSES)', () => {\r\n    expect(child.testService.id)\r\n      .toBe('parent');\r\n  });\r\n\r\n});\r\n```\r\n\r\n## 🌍  Your Environment\r\n\r\n**Angular Version:**\r\n\u003cpre>\u003ccode>\r\nAngular CLI: 10.0.8\r\nNode: 14.8.0\r\nOS: win32 x64\r\n\r\nAngular: 10.0.14\r\n... animations, common, compiler, compiler-cli, core, forms\r\n... platform-browser, platform-browser-dynamic, router\r\nIvy Workspace: Yes\r\n\r\nPackage                           Version\r\n-----------------------------------------------------------\r\n@angular-devkit/architect         0.1000.8\r\n@angular-devkit/build-angular     0.1000.8\r\n@angular-devkit/build-optimizer   0.1000.8\r\n@angular-devkit/build-webpack     0.1000.8\r\n@angular-devkit/core              10.0.8\r\n@angular-devkit/schematics        10.0.8\r\n@angular/cli                      10.0.8\r\n@ngtools/webpack                  10.0.8\r\n@schematics/angular               10.0.8\r\n@schematics/update                0.1000.8\r\nrxjs                              6.5.5\r\ntypescript                        3.9.7\r\nwebpack                           4.43.0\r\n\u003c/code>\u003c/pre>\r\n\r\n","author":{"url":"https://github.com/johncrim","@type":"Person","name":"johncrim"},"datePublished":"2020-10-28T18:19:42Z","url":"https://github.com/angular/angular/issues/39475"}

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:85cd329b-b393-da61-0f3a-b904db344b23
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE1CA:2DBB21:120F83A:180EC3C:6B012131
html-safe-nonce289484fc95f874fef51581954fc84266a0b3c4a83db19fad806f05e1a93d9c5c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMUNBOjJEQkIyMToxMjBGODNBOjE4MEVDM0M6NkIwMTIxMzEiLCJ2aXNpdG9yX2lkIjoiOTEyNjQ1MTkxODMxNzYyNTY0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacf1433f3ebae2930ae1ad2869c277f64c9aab98ab013713ad1f14f8b49d8fd0e8
hovercard-subject-tagissue:731683506
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/39475/issue_layout
twitter:imagehttps://opengraph.githubassets.com/be759a8ab50b534bb55459a93aeb8a9cc710aeebb92be4c4677ceaf11eb3093c/angular/angular/issues/39475
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/be759a8ab50b534bb55459a93aeb8a9cc710aeebb92be4c4677ceaf11eb3093c/angular/angular/issues/39475
og:image:alt🐞 bug report Affected Package @angular/core/di Is this a regression? I'm not sure, but given this workaround for bug #22560 it probably worked pre-Ivy. Description It's not possible for a component...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejohncrim
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/39475#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F39475
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%2F39475
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/39475
Reloadhttps://github.com/angular/angular/issues/39475
Reloadhttps://github.com/angular/angular/issues/39475
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/39475
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/39475
@SkipSelf() cd: ChangeDetectorRef doesn't return parent ChangeDetectorhttps://github.com/angular/angular/issues/39475#top
https://github.com/johncrim
johncrimhttps://github.com/johncrim
on Oct 28, 2020https://github.com/angular/angular/issues/39475#issue-731683506
this workaroundhttps://github.com/angular/angular/issues/22560#issuecomment-473958144
#22560https://github.com/angular/angular/issues/22560
@SkipSelfhttps://github.com/SkipSelf
InjectFlags ignored by NodeInjector.get()https://github.com/angular/angular/issues/31776#issuecomment-717398208
HostBindings not updated by detectChanges() in OnPush componenthttps://github.com/angular/angular/issues/22560
https://stackblitz.com/edit/ng10-bug-skipselfhttps://stackblitz.com/edit/ng10-bug-skipself
https://github.com/JoostK
JoostKhttps://github.com/JoostK
on Oct 28, 2020https://github.com/angular/angular/issues/39475#issuecomment-718128234
#34066https://github.com/angular/angular/issues/34066
#34819https://github.com/angular/angular/issues/34819
#39464https://github.com/angular/angular/pull/39464
JoostKhttps://github.com/JoostK
completedhttps://github.com/angular/angular/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Oct 28, 2020https://github.com/angular/angular/issues/39475#event-3932800289
https://github.com/johncrim
johncrimhttps://github.com/johncrim
on Oct 29, 2020https://github.com/angular/angular/issues/39475#issuecomment-718350668
https://github.com/apps/angular-automatic-lock-bot
angular-automatic-lock-bothttps://github.com/apps/angular-automatic-lock-bot
on Nov 29, 2020https://github.com/angular/angular/issues/39475#issuecomment-735419932
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 Nov 29, 2020https://github.com/angular/angular/issues/39475#event-4049186790
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular/issues/39475
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular/issues/39475
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.