Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components with a 'required' signalized input can not be dynamically created with createComponent #55071

Closed
PowerSupply opened this issue Mar 27, 2024 · 3 comments
Labels
area: core Issues related to the framework runtime core: dynamic view creation core: reactivity Work related to fine-grained reactivity in the core framework cross-cutting: signals
Milestone

Comments

@PowerSupply
Copy link

PowerSupply commented Mar 27, 2024

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

Components with a 'required' signalized input can not be created with createComponent without triggering NG0950.

I guess the idea is that you should use the setInput method to set a value for the required input. But the problem is that there is no way to know what inputs are required or not. This is due to an input being required or not is not part of the ComponentMirror interface as previously reported #52117.

Having to know what inputs are required or not greatly limits the ability of createComponent to actually work as a dynamic component factory. As it stands right now only components without required signal inputs can be dynamically created.

Proposed solution

I see two solutions to this:

  1. Don't error (like when @input({ required: true }) is used)
  2. Add information to each input if it is required or not to the ComponentMirror interface

Alternatives considered

The alternative is that you can not use signal inputs and stick with the old way.

@alxhub
Copy link
Member

alxhub commented Mar 27, 2024

Components with required inputs can be dynamically created, just make sure those inputs are set via .setInput() before the component is change detected.

Note that it's not possible to dynamically create an arbitrary component in a guaranteed correct way. Any component can have assumptions about how it'll be created:

  • with certain DI providers available
  • with certain inputs available (required inputs)
  • what types of values it accepts for its inputs
  • as a child of a specific other component
  • with specific content children
  • with a certain directive applied (not possible to do dynamically)

To correctly create a component, you need to meet these requirements. I don't think having the required status of inputs available via ComponentMirror is sufficient. For example, since you don't know the types of such inputs, how can you expect to provide values for them even if you know they're required?

The alternative is that you can not use signal inputs and stick with the old way.

Required inputs exist for non-signal inputs, too. If you fail to provide a value for one, the component will likely crash when it attempts to read it and gets an undefined value.

@pkozlowski-opensource pkozlowski-opensource added area: core Issues related to the framework runtime core: dynamic view creation core: reactivity Work related to fine-grained reactivity in the core framework cross-cutting: signals labels Mar 28, 2024
@ngbot ngbot bot added this to the needsTriage milestone Mar 28, 2024
@alxhub
Copy link
Member

alxhub commented Apr 9, 2024

Closing as answered - I don't think there's any more action we can take with this issue.

@alxhub alxhub closed this as not planned Won't fix, can't repro, duplicate, stale Apr 9, 2024
@PowerSupply
Copy link
Author

Hi,
Thanks for reading my issue and sorry for the late reply, I've been a bit busy.

I understand that the ComponentMirror interface will never bu fully sufficient to create an arbitrary component. But that begs the question: What decides what information goes into the interface and what information is left out?

I understand why compile time information like types can not be in the interface. But what makes, for example, templateName more useful to have in the interface than if an input is required? In my opinion it is not.

If I would have to guess; I think that the original aim of the ComponentMirror interface was to provide all the runtime information that is available about a component. But the interface was not extended when required inputs was introduced as runtime information. I believe this is a mistake, but welcome any explanation that would change my conclusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Issues related to the framework runtime core: dynamic view creation core: reactivity Work related to fine-grained reactivity in the core framework cross-cutting: signals
Projects
None yet
Development

No branches or pull requests

3 participants