René's URL Explorer Experiment


Title: Support an optional view identity key on @if branches · Issue #72095 · angular/angular · GitHub

Open Graph Title: Support an optional view identity key on @if branches · Issue #72095 · angular/angular

X Title: Support an optional view identity key on @if branches · Issue #72095 · angular/angular

Description: Which @angular/* package(s) are relevant/related to the feature request? compiler, core Description A clip editor has one selected clip, or none. While editing clip A, a user types a draft caption into a native input. If A's title change...

Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? compiler, core Description A clip editor has one selected clip, or none. While editing clip A, a user types a draft caption ...

X Description: Which @angular/* package(s) are relevant/related to the feature request? compiler, core Description A clip editor has one selected clip, or none. While editing clip A, a user types a draft caption ...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support an optional view identity key on @if branches","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\n\ncompiler, core\n\n### Description\n\nA clip editor has one selected clip, or none. While editing clip A, a user types a draft caption into a native input. If A's title changes, the input should keep its draft. If the user selects B, the new editor should start empty. Both selections satisfy the same `@if`, so Angular updates the bindings on the existing element and B inherits A's draft.\n\nThe same distinction comes up in a media preview. A one-shot GIF can keep its image element when its loading indicator goes away. Selecting a new playback session can give the entire preview fresh elements and fresh component-local state, even if the two sessions use the same asset URL. If two images need to coexist while one preloads, that's a collection and a tracked `@for` still fits.\n\n### Proposed solution\n\nAllow a conditional branch to declare what identifies its current view. One possible spelling:\n\n```html\n@if (selected(); as clip; track clip.id) {\n  \u003cinput [attr.aria-label]=\"clip.title\">\n}\n```\n\n- While the branch is active and the key stays equal, update its bindings and keep its DOM nodes and child component instances. This includes replacing the model object with a new object carrying the same ID.\n- When that branch's key changes, destroy its old view (including child teardown) and create a fresh one in the same render. Returning from B to A creates a new A view. A changed key intentionally discards local state such as focus or an unsaved draft, so the key should be stable for the life of the selection.\n- Evaluate the key only for the selected branch, with the condition alias in scope. Leaving the branch destroys its view as usual, including when the condition becomes falsy. An unkeyed branch keeps today's behavior.\n\nA design choice is whether the key should always compare the last and current evaluated values, including after an in-place object mutation. That would make a key a deliberate reset signal and would differ from `@for`'s [documented same-reference behavior](https://angular.dev/guide/templates/control-flow#why-is-track-in-for-blocks-important).\n\n### Alternatives considered\n\nWith immutable clip records, this works today:\n\n```html\n@let clip = selected();\n@for (item of clip ? [clip] : []; track item.id) {\n  \u003cinput [attr.aria-label]=\"item.title\">\n}\n```\n\nThe loop and temporary collection communicate “list” where the data model says “one optional selection.” Resetting the input's value explicitly also works for this example. It gets harder when the branch contains several stateful elements or child components. A structural directive could manage the same embedded-view lifetime, at the cost of adding an app-level directive for a template operation.\n\nRelated: #51302 proposed reloading a child component. This request puts the key on the parent's conditional branch, which can contain native elements and several children.\n\n### Reproduction on Angular 22.3.0\n\nA standalone Angular TestBed example compares actual DOM node identity and native input values. All four tests passed in a fresh Angular CLI project (CLI 22.2.8, Vitest 5.1.1, jsdom). The compiler also reports `Unrecognized conditional parameter \"track clip.id\"` for the proposed spelling.\n\n\u003cdetails>\n\u003csummary>Runnable spec\u003c/summary>\n\nSave as `src/app/view-identity.spec.ts` in a standard Angular 22 CLI app with Vitest, then run `npx ng test --watch=false --include src/app/view-identity.spec.ts`.\n\n```ts\nimport { Component, signal } from '@angular/core';\nimport { TestBed } from '@angular/core/testing';\nimport { parseTemplate } from '@angular/compiler';\nimport { describe, expect, it } from 'vitest';\n\ninterface Clip {\n  id: string;\n  title: string;\n}\n\n@Component({\n  standalone: true,\n  template: `\n    @let clip = selected();\n    @if (clip) {\n      \u003cinput class=\"plain\" [attr.aria-label]=\"clip.title\">\n    }\n    @for (item of clip ? [clip] : []; track item.id) {\n      \u003cinput class=\"keyed\" [attr.aria-label]=\"item.title\">\n    }\n  `,\n})\nclass ClipEditor {\n  readonly selected = signal\u003cClip | null>({ id: 'A', title: 'First clip' });\n}\n\nfunction mountEditor() {\n  const fixture = TestBed.createComponent(ClipEditor);\n  const host: HTMLElement = fixture.nativeElement;\n  fixture.detectChanges();\n\n  function input(kind: 'plain' | 'keyed') {\n    const node = host.querySelector\u003cHTMLInputElement>('input.' + kind);\n    if (!node) throw new Error('Expected the ' + kind + ' input to be mounted');\n    return node;\n  }\n\n  function select(clip: Clip | null) {\n    fixture.componentInstance.selected.set(clip);\n    fixture.detectChanges();\n  }\n\n  return { host, input, select };\n}\n\ndescribe('one selected clip', () => {\n  it('updates bindings but keeps both inputs and their drafts for the same ID', () => {\n    const { input, select } = mountEditor();\n    const plain = input('plain');\n    const keyed = input('keyed');\n    plain.value = 'Draft A';\n    keyed.value = 'Draft A';\n\n    select({ id: 'A', title: 'Updated title' });\n\n    expect(input('plain')).toBe(plain);\n    expect(input('keyed')).toBe(keyed);\n    for (const node of [plain, keyed]) {\n      expect(node.getAttribute('aria-label')).toBe('Updated title');\n      expect(node.value).toBe('Draft A');\n    }\n  });\n\n  it('keeps the plain input but replaces the tracked input when the ID changes', () => {\n    const { input, select } = mountEditor();\n    const plain = input('plain');\n    const keyed = input('keyed');\n    plain.value = 'Draft A';\n    keyed.value = 'Draft A';\n\n    select({ id: 'B', title: 'Second clip' });\n\n    expect(input('plain')).toBe(plain);\n    expect(plain.getAttribute('aria-label')).toBe('Second clip');\n    expect(plain.value).toBe('Draft A');\n    expect(input('keyed')).not.toBe(keyed);\n    expect(input('keyed').getAttribute('aria-label')).toBe('Second clip');\n    expect(input('keyed').value).toBe('');\n  });\n\n  it('removes both inputs on clear and creates fresh ones when the same clip returns', () => {\n    const { host, input, select } = mountEditor();\n    const plain = input('plain');\n    const keyed = input('keyed');\n\n    select(null);\n    expect(host.querySelectorAll('input')).toHaveLength(0);\n\n    select({ id: 'A', title: 'First clip' });\n    expect(input('plain')).not.toBe(plain);\n    expect(input('keyed')).not.toBe(keyed);\n  });\n\n  it('reports the proposed track clause as an unsupported conditional parameter', () => {\n    const template = '@if (selected(); as clip; track clip.id) { \u003cinput> }';\n    const { errors } = parseTemplate(template, 'example.html');\n    expect(errors?.map(error => error.msg)).toContain('Unrecognized conditional parameter \"track clip.id\"');\n  });\n});\n```\n\n\u003c/details>\n","author":{"url":"https://github.com/EthanSK","@type":"Person","name":"EthanSK"},"datePublished":"2026-11-18T22:29:33Z","url":"https://github.com/angular/angular/issues/72095"}

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:4dd9f309-6232-1838-dc41-1bd3f18c894c
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9578:1FE434:FFEE55:152443D:6B01DB7F
html-safe-noncec5f856229b16cff2b0f09e10856b929439d43d44b642eab3f6205696ac8bc51c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NTc4OjFGRTQzNDpGRkVFNTU6MTUyNDQzRDo2QjAxREI3RiIsInZpc2l0b3JfaWQiOiIxNzQ3MTExNTU3Mjg1OTI3ODA3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmaca4e09f5ef25bea797bc7f5afd29c4883cc62e7f5596cf6506f5a90f57799cdce
hovercard-subject-tagissue:6478032947
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/72095/issue_layout
twitter:imagehttps://opengraph.githubassets.com/598af413671eccc7a60ea41295cc62fdeeaf6db65ab1ca2700658a4d7fac3565/angular/angular/issues/72095
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/598af413671eccc7a60ea41295cc62fdeeaf6db65ab1ca2700658a4d7fac3565/angular/angular/issues/72095
og:image:altWhich @angular/* package(s) are relevant/related to the feature request? compiler, core Description A clip editor has one selected clip, or none. While editing clip A, a user types a draft caption ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameEthanSK
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/72095#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F72095
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%2F72095
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/72095
Reloadhttps://github.com/angular/angular/issues/72095
Reloadhttps://github.com/angular/angular/issues/72095
angularhttps://github.com/angular
angularhttps://github.com/angular/angular
Codehttps://github.com/angular/angular
Issues835 (835)https://github.com/angular/angular/issues
Pull requests142 (142)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/72095
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/72095
Support an optional view identity key on @if brancheshttps://github.com/angular/angular/issues/72095#top
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
needsTriagehttps://github.com/angular/angular/milestone/83
https://github.com/EthanSK
EthanSKhttps://github.com/EthanSK
on Nov 18, 2026https://github.com/angular/angular/issues/72095#issue-6478032947
documented same-reference behaviorhttps://angular.dev/guide/templates/control-flow#why-is-track-in-for-blocks-important
#51302https://github.com/angular/angular/issues/51302
angular-robothttps://github.com/apps/angular-robot
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
on Nov 18, 2026https://github.com/angular/angular/issues/72095#event-36586195010
angular-robothttps://github.com/apps/angular-robot
needsTriagehttps://github.com/angular/angular/milestone/83
on Nov 18, 2026https://github.com/angular/angular/issues/72095#event-36586197583
https://github.com/Flarette
Flarettehttps://github.com/Flarette
on Nov 20, 2026https://github.com/angular/angular/issues/72095#issuecomment-7038753548
#72140https://github.com/angular/angular/issues/72140
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular/issues/72095
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular/issues/72095
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
needsTriageNo due datehttps://github.com/angular/angular/milestone/83
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.