-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
build: add a script to detect component ID collisions #27411
Conversation
Why does Angular throw an error here? Isn't our use case valid - we are making a new version of a component. |
tl;dr is that Angular has always had a unique ID for each component. Pre-v16 the ID was based on a counter so components were guaranteed to have a unique ID. When hydration was introduced, the counter approach didn't work anymore since different components might be executed on the server and the client so the ID algorithm was switched to use the metadata instead. The unique ID is used in DI and when keeping track of stylesheets. |
Could the ID generation take into account it's filepath or something unique beyond just metadata? It'd be helpful to know they intend to prevent this case otherwise |
It can't because:
|
Oof...well that's a bummer. When should we run this script? Seems like it's a proactive thing that we ought to run when we change metadata? EDIT: Or include it in a CI test? |
There are a few failures that I want to address first before I add it to the CI. |
Two quick thoughts:
|
Things don't necessarily break at the moment, they just log a warning and I wanted to automate catching the warnings instead of having users report it to us. As for having it in the compiler: I think it's trickier to do it there, because compilations might be spread across different build units running in parallel and things would only conflict once they're on the same page. |
I thought we could potentially intercept logging and see if there is a matching error/or something, without having to replicate some of the serialization logic. At the same time though- adding all components is likely not super nice either |
Yeah I feel like having it run as a part of the CI against the source code is the simplest without having to maintain even more code. |
// Create an ID for the component based on its metadata. This is based on what the framework | ||
// does at runtime at https://github.com/angular/angular/blob/main/packages/core/src/render3/definition.ts#L679. | ||
// Note that the behavior isn't exactly the same, because the framework uses some fields that | ||
// are generated by the compiler based on the component's template. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and likely we are overly sensitive here, but it guarantees we are not conflicting.
As of v16, the framework uses the metadata of a component to generate an ID. If two components have identical metadata, they may end up with the same ID which will log a warning. These changes add a script to detect such cases automatically. Relates to angular#27163.
As of v16, the framework uses the metadata of a component to generate an ID. If two components have identical metadata, they may end up with the same ID which will log a warning. These changes add a script to detect such cases automatically. Relates to angular#27163.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
As of v16, the framework uses the metadata of a component to generate an ID. If two components have identical metadata, they may end up with the same ID which will log a warning. These changes add a script to detect such cases automatically.
Relates to #27163.