-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
[Bug]: Missing ng* parameters for elements injected with ng-content (Angular) #24813
Comments
Hi, from what I have observed, it seems that your counter component is experiencing an issue with loading. After examining 'badge.component.stories.ts,' I noticed that you declared a component named 'ds-badge,' and as a result, it is loading the badge component first. When I changed it to the counter component, it loaded the counter component instead. Therefore, you may need to maintain two separate files for this |
Hi @jagdishpatil02, thanks for reply. I want to visualize the counter inside the the badge component. I cannot have two separate files for this use case. The question is why on the initial load, the counter is not rendered in a different color and I have to change the type from the arguments that it works. I think this is a bug in storybook. |
I just found applying the metadata on the "meta"-level works correctly, but why should not I have the option to apply it on the story level, if moduleMetadata can be applied here as well. |
@markusnissl, Yup that might be the bug, also there is one more property i.e. subcomponents, maybe you can try that out. |
I see the problem and I have a potential fix. I am testing my fix and will try to submit a PR for it tomorrow, unless I find that my change breaks something else or someone else takes care of it first. It seems to be a problem that I was worried about when I first saw that part of the code, but I hadn't seen any issues about it. Now that I am debugging it, I am really surprised there haven't been more issues for this. WorkaroundYou can disable inline rendering for that story, so it is rendered in an iframe and doesn't inherit the NgModule built for the previous story, which seems to be happening currently. export const WithCounter: StoryWithCounter = {
parameters: {
docs: {
story: {
inline: false,
},
},
},
...,
} ProblemThe problem appears to be the following block, which I think should not be avoiding the rebuilding of the NgModule. It may be an unnecessary step in most scenarios, but causes issues if the metadata changes, when decorators or render function are called. It also causes the metadata from the first story that uses that component to carry over to other stories, which is the problem here. storybook/code/frameworks/angular/src/client/angular-beta/StorybookWrapperComponent.ts Lines 63 to 79 in bffa2db
|
@Marklb I would appreciate any kind of help improving this logic! This logic was mainly introduced to circumvent the "Type X is part of the declarations of 2 modules: StorybookComponentModule and StorybookComponentModule! ..." error. I don't like this part of the implementation and I would like to get rid of the caching mechanism completely. I am curious, whether you can find out the root cause of the Error and solving it differently. |
@markusnissl I don't think they are related, but may have actually got an idea about that one from something else I saw, while I was debugging this one. I can't check at the moment, but I will check what I am thinking tomorrow. |
@valentinpalkovic That error is what I thought the caching may have been for, and is why I was going to add more tests before I opened a PR. I have some other scenarios I was going to test for, but that may be a bigger issue. I will take a look, though. |
The multiple declarations did end up being a problem, when I started testing. I thought I had an idea, but I ended up finding similar problems. My change would fix some cases, but break others. I am recreating the problem in an Angular app that has a very overly simplified implementation of what the Storybook framework does and I am going to see if that helps get some ideas from someone that maybe knows the internals Angular well, but isn't familiar with Storybook. |
I am still testing it, but I opened a draft PR with the change that seems to be working in a local reproduction. I am still not positive that it is the correct fix, but it does work on the cases that caused me to abandon my first solution. #24982 My solution is still the original idea of removing the cached NgModules, but I added a lock to make sure multiple Angular apps are not getting bootstrapped at the same time. |
Describe the bug
I am overriding the template in the render method using Angular as follow:
where the ds-badge component contains following HTML
This results in docs being rendered as the following HTML:
As soon as I change a property in the controls, it gets updated to (which is correct)
So, the initial rendering of the docs somehow does not initialize the elements injected with ngcontent as the _ng* parameters are missing on the ds-counter component.
To Reproduce
https://stackblitz.com/~/github.com/markusnissl/storybook-demo
You see the background color of the number 10 is changing after the first interaction (Badge Component, With Counter).
System
Additional context
No response
The text was updated successfully, but these errors were encountered: