Skip to content

fix(metadata): wrap signal query predicates in forwardRef in setClassMetadata - #602

Merged
Brooooooklyn merged 1 commit into
voidzero-dev:mainfrom
encharm:fix/class-metadata-forward-ref
Oct 22, 2026
Merged

Brooooooklyn merged 1 commit into
voidzero-dev:mainfrom
encharm:fix/class-metadata-forward-ref

Conversation

@Rush

@Rush Rush commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

A signal query whose predicate is a class declared later in the file:

@Component({ selector: 'd-parent', template: '<ng-content />' })
export class DParent {
  panes = contentChildren(DPane);
}
@Component({ selector: 'd-pane', template: '' })
export class DPane {}

emitted setClassMetadata(DParent, ..., { panes: [{ type: i0.ContentChildren, args: [DPane, { isSignal: true }] }] }). setClassMetadata runs as soon as the class is defined, so in development builds DPane was read before its initialization: ReferenceError: Cannot access 'DPane' before initialization, which stops the app. (The query initializer itself is fine: it runs later.)

ngtsc's memberMetadataFromSignalQuery wraps the predicate in forwardRef unless it is a string or a call expression, for this reason; this does the same:

panes: [{ type: i0.ContentChildren, args: [i0.forwardRef(() => DPane), { isSignal: true }] }]

It applies whatever the declaration order, as in ngtsc. A string predicate (viewChildren('ref')) and decorator queries are left as written. One deliberate difference: a spread first argument (viewChild(...args)) isn't wrapped, since forwardRef(() => ...args) isn't valid JavaScript.

tests/signal_query_metadata_forward_ref_test.rs checks both declaration orders, an options object ({ ...{ read: ElementRef }, isSignal: true }), a string predicate and decorator queries against @angular/compiler-cli 21.0.1's output.

…Metadata

`contentChildren(Pane)` in a class declared before `Pane` emitted
`setClassMetadata(..., { panes: [{ type: i0.ContentChildren, args: [Pane, ...] }] })`,
which reads `Pane` as soon as the class is defined: a TDZ ReferenceError in
development builds. Like ngtsc's `memberMetadataFromSignalQuery`, a predicate
other than a string or a call is now `i0.forwardRef(() => Pane)`.
@Brooooooklyn

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 06efd1888e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/oxc_angular_compiler/src/class_metadata/builders.rs
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T12:52:46.032653Z 06efd18 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Brooooooklyn
Brooooooklyn merged commit 815b277 into voidzero-dev:main Oct 22, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants