Skip to content

Angular: Remove usage of ComponentFactoryResolver#34535

Merged
JReinhold merged 1 commit into
nextfrom
jeppe/fix-angular-component-factory-resolver-dependency
Apr 14, 2026
Merged

Angular: Remove usage of ComponentFactoryResolver#34535
JReinhold merged 1 commit into
nextfrom
jeppe/fix-angular-component-factory-resolver-dependency

Conversation

@JReinhold
Copy link
Copy Markdown
Contributor

@JReinhold JReinhold commented Apr 14, 2026

What I did

The release of Angular 22.0.0-next.7 removed the exports of ComponentFactoryResolver and ComponentFactory. We relied on these in a few unit tests and stories, that I've now removed. We should try to add them in later in a way that doesn't depend on the removed APIs.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

See the Angular prerelease sandboxes not failing.

Caution

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • Tests

    • Disabled test case and deprecated API imports.
  • Chores

    • Removed several demo components for complex selectors and their associated Storybook story configurations.

@JReinhold JReinhold added angular build Internal-facing build tooling & test updates ci:daily Run the CI jobs that normally run in the daily job. labels Apr 14, 2026
@JReinhold JReinhold self-assigned this Apr 14, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 14, 2026

View your CI Pipeline Execution ↗ for commit b058e01

Command Status Duration Result
nx run-many -t compile,check,knip,test,lint,fmt... ✅ Succeeded 11m 17s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-14 09:56:35 UTC

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 14, 2026

View your CI Pipeline Execution ↗ for commit b058e01


☁️ Nx Cloud last updated this comment at 2026-04-14 09:43:41 UTC

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

Removal of Angular components and Storybook stories from the "component-with-complex-selectors" directory that relied on ComponentFactoryResolver, which was removed in Angular 22. Additionally, test code using this API was commented out with a compatibility note.

Changes

Cohort / File(s) Summary
Test Updates
code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.test.ts
Commented out ComponentFactoryResolver import and test case relying on resolveComponentFactory() helper due to Angular 22 removal; helper function also commented out.
Complex Selector Components and Stories
code/frameworks/angular/template/stories/basics/component-with-complex-selectors/attribute-selector.component.ts, attribute-selectors.component.stories.ts, class-selector.component.ts, class-selector.component.stories.ts, multiple-class-selector.component.stories.ts, multiple-selector.component.ts, multiple-selector.component.stories.ts
Removed seven files containing AttributeSelectorComponent, ClassSelectorComponent, MultipleSelectorComponent, and MultipleClassSelectorComponent along with their associated Storybook story definitions. All components relied on ComponentFactoryResolver to dynamically resolve component factories and extract selector metadata.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.test.ts (1)

50-212: ⚠️ Potential issue | 🟠 Major

Re-enable positive-path getComponentInputsOutputs tests instead of block-commenting them.

This removes most behavioral coverage for getComponentInputsOutputs and leaves only the empty-path assertion. Please keep these tests active and decouple them from factory-based assertions (assert explicit expected inputs/outputs only).

Suggested direction
-  /* Commented out until we figure out how to handle the removal of ComponentFactoryResolver in Angular 22
-  ...
-  */
+  it('should return I/O', () => {
+    // keep component setup
+    const { inputs, outputs } = getComponentInputsOutputs(FooComponent);
+    expect({ inputs, outputs }).toEqual({
+      inputs: [
+        { propName: 'inputInComponentMetadata', templateName: 'inputInComponentMetadata' },
+        { propName: 'input', templateName: 'input' },
+        { propName: 'inputWithBindingPropertyName', templateName: 'inputPropertyName' },
+      ],
+      outputs: [
+        { propName: 'outputInComponentMetadata', templateName: 'outputInComponentMetadata' },
+        { propName: 'output', templateName: 'output' },
+        { propName: 'outputWithBindingPropertyName', templateName: 'outputPropertyName' },
+      ],
+    });
+  });
+  // Apply the same pattern to the other currently-commented cases in this block.

Based on learnings, “Export functions that need direct tests and test real behavior, not just syntax patterns.”

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.test.ts`
around lines 50 - 212, The tests for getComponentInputsOutputs were commented
out, removing behavioral coverage; re-enable the positive-path tests but remove
reliance on resolveComponentFactory (decouple from Angular factory internals) by
asserting explicit expected inputs/outputs returned from
getComponentInputsOutputs for the various component classes in the file
(NgComponentAnalyzer.test.ts); keep tests that define FooComponent/BarComponent
variants and call getComponentInputsOutputs(FooComponent) and assert the exact
inputs/outputs objects (including alias/templateName cases, multiple decorators,
and inheritance) rather than comparing to fooComponentFactory inputs/outputs, so
tests exercise getComponentInputsOutputs directly.
🧹 Nitpick comments (1)
code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.test.ts (1)

378-387: Delete the commented-out resolveComponentFactory helper to avoid dead-code drift.

If this helper is intentionally deferred, track it in an issue/PR note rather than leaving a commented implementation in the test file.

Cleanup diff
-/*
-function resolveComponentFactory<T extends Type<any>>(component: T) {
-  TestBed.configureTestingModule({
-    declarations: [component],
-  }).overrideModule(BrowserDynamicTestingModule, {});
-  const componentFactoryResolver = TestBed.inject(ComponentFactoryResolver);
-
-  return componentFactoryResolver.resolveComponentFactory(component);
-}
-*/
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.test.ts`
around lines 378 - 387, Remove the commented-out helper resolveComponentFactory
and its block to eliminate dead-code drift; locate the commented function named
resolveComponentFactory (which references TestBed, BrowserDynamicTestingModule,
and ComponentFactoryResolver) in NgComponentAnalyzer.test.ts and delete the
entire commented implementation, or if it's intentionally deferred add a note
pointing to an issue/PR instead of leaving the commented code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In
`@code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.test.ts`:
- Around line 50-212: The tests for getComponentInputsOutputs were commented
out, removing behavioral coverage; re-enable the positive-path tests but remove
reliance on resolveComponentFactory (decouple from Angular factory internals) by
asserting explicit expected inputs/outputs returned from
getComponentInputsOutputs for the various component classes in the file
(NgComponentAnalyzer.test.ts); keep tests that define FooComponent/BarComponent
variants and call getComponentInputsOutputs(FooComponent) and assert the exact
inputs/outputs objects (including alias/templateName cases, multiple decorators,
and inheritance) rather than comparing to fooComponentFactory inputs/outputs, so
tests exercise getComponentInputsOutputs directly.

---

Nitpick comments:
In
`@code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.test.ts`:
- Around line 378-387: Remove the commented-out helper resolveComponentFactory
and its block to eliminate dead-code drift; locate the commented function named
resolveComponentFactory (which references TestBed, BrowserDynamicTestingModule,
and ComponentFactoryResolver) in NgComponentAnalyzer.test.ts and delete the
entire commented implementation, or if it's intentionally deferred add a note
pointing to an issue/PR instead of leaving the commented code.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d2ec3195-928d-4588-a669-ac05e1270e5a

📥 Commits

Reviewing files that changed from the base of the PR and between c6bb9f5 and b058e01.

📒 Files selected for processing (8)
  • code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.test.ts
  • code/frameworks/angular/template/stories/basics/component-with-complex-selectors/attribute-selector.component.ts
  • code/frameworks/angular/template/stories/basics/component-with-complex-selectors/attribute-selectors.component.stories.ts
  • code/frameworks/angular/template/stories/basics/component-with-complex-selectors/class-selector.component.stories.ts
  • code/frameworks/angular/template/stories/basics/component-with-complex-selectors/class-selector.component.ts
  • code/frameworks/angular/template/stories/basics/component-with-complex-selectors/multiple-class-selector.component.stories.ts
  • code/frameworks/angular/template/stories/basics/component-with-complex-selectors/multiple-selector.component.stories.ts
  • code/frameworks/angular/template/stories/basics/component-with-complex-selectors/multiple-selector.component.ts
💤 Files with no reviewable changes (7)
  • code/frameworks/angular/template/stories/basics/component-with-complex-selectors/class-selector.component.stories.ts
  • code/frameworks/angular/template/stories/basics/component-with-complex-selectors/class-selector.component.ts
  • code/frameworks/angular/template/stories/basics/component-with-complex-selectors/attribute-selector.component.ts
  • code/frameworks/angular/template/stories/basics/component-with-complex-selectors/multiple-selector.component.stories.ts
  • code/frameworks/angular/template/stories/basics/component-with-complex-selectors/multiple-selector.component.ts
  • code/frameworks/angular/template/stories/basics/component-with-complex-selectors/attribute-selectors.component.stories.ts
  • code/frameworks/angular/template/stories/basics/component-with-complex-selectors/multiple-class-selector.component.stories.ts

@JReinhold JReinhold moved this to Empathy Backlog in Core Team Projects Apr 14, 2026
@JReinhold JReinhold moved this from Empathy Backlog to Done in Core Team Projects Apr 14, 2026
@JReinhold JReinhold merged commit f09ada2 into next Apr 14, 2026
305 of 317 checks passed
@JReinhold JReinhold deleted the jeppe/fix-angular-component-factory-resolver-dependency branch April 14, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

angular build Internal-facing build tooling & test updates ci:daily Run the CI jobs that normally run in the daily job.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants