`$safeNavigationMigration(...)` in an event listener reads template locals from the wrong context
Maintainer antworten meist innerhalb von 1 Tag
Ein zugehöriger Pull Request wurde bereits gemerged.
- #587 von @edbzn — gemerged
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 55/100
Rechercherichtung
Start by reading remove_safe_navigation_migration and the name resolution phase that handles listener handlerOps; the issue identifies both as possible points where the local scope is lost. Compare listener compilation with the working property binding in a focused reproduction using the supplied template. Done when the listener reads the restored option_r2 value and a regression test covers template locals inside migrated listener expressions.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
When $safeNavigationMigration(expr) is used inside an event binding, OXC resolves template-local
variables in expr (@for items, @if … as x aliases, let- variables) against the listener's
ctx (ctx.option) instead of the local restored from the view (option_r2). The argument is
always undefined, so the expression evaluates to null.
Property bindings that use the same builtin compile correctly. The bug is specific to listener
handler ops.
Reproduction (@oxc-angular/[email protected], @oxc-angular/vite/api)
import { transformAngularFile } from '@oxc-angular/vite/api';
const src = `import { Component } from '@angular/core';
@Component({ selector: 'x-probe', template: \`
@for (option of options; track $index) {
<button (click)="pick(option?.value); pick2($safeNavigationMigration(option?.value))"
[title]="$safeNavigationMigration(option?.label)"></button>
}\` })
export class Probe { options: any[] = []; pick(v: any) {} pick2(v: any) {} }`;
const r = await transformAngularFile(src, '/tmp/probe.component.ts', {}, { templates: {}, styles: {} });
console.log(r.code);
Actual
i0.ɵɵlistener("click", function Probe_For_1_Template_button_click_0_listener() {
const option_r2 = i0.ɵɵrestoreView(_r1).$implicit;
const ctx_r2 = i0.ɵɵnextContext();
ctx_r2.pick(((option_r2 == null) ? null : option_r2.value)); // correct
return i0.ɵɵresetView(ctx_r2.pick2(((ctx.option == null) ? null : ctx.option.value))); // wrong: ctx.option
});
// update block, correct:
i0.ɵɵproperty("title", ((option_r3 == null) ? null : option_r3.label));
Expected (what ngc emits)
The listener should read option_r2 for both calls:
ctx_r2.pick2(((option_r2 == null) ? null : option_r2.value)).
Impact
Angular's ng update migration for the v22 safe-navigation change inserts $safeNavigationMigration
automatically. Any migrated listener such as (click)="select($safeNavigationMigration(item?.id))"
inside @for/@if as/*ngFor now passes null at runtime. There's no compile error. In our
monorepo this broke a shared select component (every dropdown emitted null) and profile
activation toggles, and failed 21 component tests across 4 projects that pass under
@analogjs/vite-plugin-angular / ngc. Rewriting the three affected bindings as x?.y ?? null
made all 21 pass under OXC.
Possible cause
remove_safe_navigation_migration iterates view.create and view.update. Angular's
unit.ops() also yields each listener's handlerOps. If the marker in handler ops isn't converted
before resolve_names, or is converted with a different scope, the argument's LexicalReads skip
the restored-view locals. Unverified, this is a guess from reading the phase source.
Environment
@oxc-angular/vite0.0.41 (linux-x64-gnu binding)- Angular 22.2.0, Vite 7.3.6
- Vorherrschende Sprache
- Rust
- Sterne
- 240
- Forks
- 24
- Ø Merge
- 1 T. 15 Std.
- Gemergte PRs (30 T.)
- 75
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus voidzero-dev/oxc-angular-compiler
-
fix(directive): input names with lone surrogates are emitted in oxc's internal U+FFFD encodingOffenbug
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 68/100
voidzero-dev/oxc-angular-compiler#505 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Support useDefineForClassFields: false (Class Field Lowering)Evtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
voidzero-dev/oxc-angular-compiler#73 · 11 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Angular 21.2.0 + @oxc-angular/vite 0.0.7 SSR runtime parity regressions (RouterLinkActive, Forms DI, Apollo DI) require app-level shimsEvtl. wieder frei @Brooooooklyn hat das vor 231 Tagen übernommen, und es ist kein Pull Request offen. Offen
voidzero-dev/oxc-angular-compiler#61 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Angular 21.2.0 + @oxc-angular/vite 0.0.7 SSR: AngularNodeAppEngine is unusable (missing app-engine manifest)Evtl. wieder frei @Brooooooklyn hat das vor 231 Tagen übernommen, und es ist kein Pull Request offen. Offen
voidzero-dev/oxc-angular-compiler#60 · 4 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in voidzero-dev/oxc-angular-compiler
Ähnliche Issues
-
Update webpki-root-certsOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
rustls/rustls-platform-verifier#262 · 2 Kommentare · 2 Reaktionen ·
-
needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 73/100
bherbruck/solvecraft#4493 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
IngvarConsulting/unica#1911 ·
Maintainer antworten meist innerhalb von 1 Tag