Skip to content

fix(partial): ɵɵngDeclareComponent omits queries / viewQueries #513

Description

@Brooooooklyn

With compilationMode: 'partial', components lose all their queries. Directives are fine. After linking, @ViewChild / @ContentChild on a library component is never set.

Repro (compilationMode: 'partial')

import {Component, Directive, ViewChild, ContentChild, ElementRef} from '@angular/core';
@Component({selector: 'c', template: '<div #a></div>'})
export class C { @ViewChild('a') q!: ElementRef; @ContentChild('b') c: any; }
@Directive({selector: '[d]'})
export class D { @ViewChild('a') q!: ElementRef; @ContentChild('b') c: any; }

OXC (main and #504 tip)

static ɵcmp = i0.ɵɵngDeclareComponent({minVersion:"14.0.0",version:"0.0.0-PLACEHOLDER",type:C,selector:"c",
    ngImport:i0,template:"<div #a></div>",isInline:true});
static ɵdir = i0.ɵɵngDeclareDirective({minVersion:"14.0.0",version:"0.0.0-PLACEHOLDER",type:D,selector:"[d]",
    queries:[{propertyName:"c",first:true,predicate:["b"],descendants:true}],viewQueries:[{propertyName:"q",first:true,predicate:["a"],descendants:true}],ngImport:i0});

ngtsc 22.1.7

static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.1.7", type: C, isStandalone: true, selector: "c", queries: [{ propertyName: "c", first: true, predicate: ["b"], descendants: true }], viewQueries: [{ propertyName: "q", first: true, predicate: ["a"], descendants: true }], ngImport: i0, template: '<div #a></div>', isInline: true });

Where

crates/oxc_angular_compiler/src/partial/component.rs (compile_declare_component_from_metadata) builds from ComponentMetadata, which has no query fields. partial/directive.rs has queries / viewQueries (and the 17.2.0 signal-query version bump). The comment in partial/component.rs ("Signal queries — ... the metadata struct doesn't include them") notes this gap.

On main?

Yes.

Direction

Pass the component's content and view queries (decorator, queries: and signal queries) to the partial component emitter. Reuse the directive's compile_queries_array and its minVersion bump.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions