Skip to content

Commit 02965bb

Browse files
committed
fix(multiple): resolve forward ref errors (#32413)
The combobox and listbox had some cases where they were referencing classes defined further down in the file in their queries. When the references are extracted into Angular's metadata, this can cause an error at runtime because the reference becomes eager. These changes wrap the problematic cases in `forwardRef` to resolve the issues. Fixes #32408. (cherry picked from commit 9fff253)
1 parent 0cc3abd commit 02965bb

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/aria/combobox/combobox.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
contentChild,
1414
Directive,
1515
ElementRef,
16+
forwardRef,
1617
inject,
1718
input,
1819
model,
@@ -98,7 +99,12 @@ export class Combobox<V> {
9899
private readonly _deferredContentAware = inject(DeferredContentAware, {optional: true});
99100

100101
/** The combobox popup. */
101-
readonly popup = contentChild<ComboboxPopup<V>>(ComboboxPopup);
102+
readonly popup = contentChild<ComboboxPopup<V>>(
103+
// We need a `forwardRef` here, because the popup class is declared further down
104+
// in the same file. When the reference is written to Angular's metadata this can
105+
// cause an attempt to access the class before it's defined.
106+
forwardRef(() => ComboboxPopup),
107+
);
102108

103109
/**
104110
* The filter mode for the combobox.

src/aria/listbox/listbox.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
contentChildren,
1414
Directive,
1515
ElementRef,
16+
forwardRef,
1617
inject,
1718
input,
1819
model,
@@ -81,7 +82,13 @@ export class Listbox<V> {
8182
private readonly _directionality = inject(Directionality);
8283

8384
/** The Options nested inside of the Listbox. */
84-
private readonly _options = contentChildren(Option, {descendants: true});
85+
private readonly _options = contentChildren(
86+
// We need a `forwardRef` here, because the option class is declared further down
87+
// in the same file. When the reference is written to Angular's metadata this can
88+
// cause an attempt to access the class before it's defined.
89+
forwardRef(() => Option),
90+
{descendants: true},
91+
);
8592

8693
/** A signal wrapper for directionality. */
8794
protected textDirection = toSignal(this._directionality.change, {

0 commit comments

Comments
 (0)