Closed kbrilla closed 3 years ago
Yes, it's true. But I don't think it's a "bug". ๐ (but a change in behaviour that I would also like to make). Give me a few days to find time to make a complete answer. (very busy lately ๐ )
Well I donโt think storybook should change in any way properties that are not inputs and are even private (i know ts private is come and take It). But, sure will wiat for update on Your side. For now will keep legacy rendering on.
W dniu ลr., 10.03.2021 o 08:48 ThibaudAV @.***> napisaล(a):
Yes, it's true. But I don't think it's a "bug". ๐ Give me a few days to find time to make a complete answer. (very busy lately ๐ )
โ You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/storybookjs/storybook/issues/14147#issuecomment-795037493, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFKBQQJZ3Y24YTJABFG6NVDTC4P5DANCNFSM4YVC2VIQ .
In fact I don't know where to start... many things are mixed up
If I understand correctly your example is this:
here are the steps I do :
Add story without angularLegacyRendering: true
run yarn storybook
see the console.log
{input1: undefined, notInputProperty: undefined, ngOnChanges: undefined}
change input1
value with controls
nothing happen but i have log + error in console :
change with angularLegacyRendering: true
see the console.log
{}
:wow: empty now
change input1
value with controls
see the console.log
{input1: "s"}
It works, we can see Koko in canvas
Now, if i do same step (close storybook client and restart it) but i start storybook with angularLegacyRendering: true
I have the same behavior. So, If it's the same problem you encountered, the problem is not the new rendering I'm not mistaken? ๐
I think the problem comes from compodoc. Which discovers all properties of your component class and adds them to agrs. If you don't control it, it will do anything.
Discussions are already in progress to replace compodoc https://github.com/storybookjs/storybook/issues/12689 https://github.com/storybookjs/storybook/issues/8672
personally I don't like compodoc at all and I don't use it
I recommend you not to trust compodoc if you use it and to do something like :
const Template: Story<SampleComp> = (args) => ({
props: {
input1: args.input1
},
});
to be sure to send only the expected "arg"
compodoc
reference private propertiesWait for an alternative. or manually add controls of args
props
can override private (or non @input) properties of components Several topics are talking about it, it also blocks some features I have already made a response in some of them
https://github.com/storybookjs/storybook/issues/11613 https://github.com/storybookjs/storybook/issues/12946
or else https://github.com/storybookjs/storybook/issues/12438
I really wish I could ban it or split it into 2 like:
props
: only angular Input / Output / directive (ngClass,...) or html attributs (class,...)
overrideComponentProperties
: As before allows to override a property of the component class
but this is a big breaking changes I think and we have to wait for a major version (I was told) ๐
fun fact: after first time storybooks renders You will change the name of property to lets say notInputProperty2 then it will work! So maybe it has something to do with controls?
not with controls with compodoc. As you do not completely reload the storybook client compodoc does not reanalyze your component
I don't recommend to use legacy rendering if you have stories and component with ngOnchanges. it is manually called by the renderer and is not exactly the same as native angular. see: https://github.com/storybookjs/storybook/blob/a8770a4a8e69b441b56cc3c2a1e906e913e0907c/app/angular/src/client/preview/angular/components/app.component.ts#L119
The new renderer doesn't work the same way because it simulates a template for your component and therefore lets the native angular mechanism do the work
A possible fix until the main issue gets fixed you can disable compodoc
in main.js
. But as a result you have to declare the argTypes
on all components and maintain it.
// Because of the following issues we cannot use Compodoc to automatically find component inputs:
// https://github.com/storybookjs/storybook/issues/14147
// https://github.com/storybookjs/storybook/issues/11613
// It seems storybook will try to add support for detecting inputs because compodoc is not maintained anymore and they end up overriding angular component
// props which are not imputs with ng versions bigger than 8.0
// When this is closed we can probably see what's the upgrade path: https://github.com/storybookjs/storybook/issues/8672
// import { setCompodocJson } from "@storybook/addon-docs/angular";
import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
// import docJson from "../documentation.json";
// setCompodocJson(docJson);
export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
viewport: {
viewports: INITIAL_VIEWPORTS,
},
}
@ThibaudAV
legacy rendering and ngOnChanges
I don't recommend to use legacy rendering if you have stories and component with ngOnchanges. it is manually called by the renderer and is not exactly the same as native angular. see:
We turned on legacyRendering because we got these kinds of errors:
ERROR TypeError: provider.ngAfterViewInit is not a function
How would we turn off angularLegacyRendering and solving the above error?
@salmin89 can you give more details about the component you added in the story ?
Make sure that you do not directly pass all args
in your story props
prefer a "destructuring" to control them :
const Template: Story<SampleComp> = (args) => ({
props: {
input1: args.input1
},
});
I think we can close it a workaround has been added to avoid the override can you check if the problem is still present with the last version ๐
Hi, the problem still persists and the workaround also doesn't work anymore.
Storybook: v6.50-alpha.14 Compodoc: v1.1.18 Angular: v13
In case it helps anyone else who ends up here I added --disablePrivate
, --disableInternal
and --disableLifeCycleHooks
to the storybook builder compodocArgs
options to get it to stop finding the private properties.
Added in the angular.json
:
{
...
"projects": {
"my-lib": {
...
"architect": {
"storybook": {
"builder": "@storybook/angular:start-storybook",
"options": {
...
"compodocArgs": ["-e", "json", "--disablePrivate", "--disableInternal", "--disableLifeCycleHooks"]
}
},
Another workaround that I don't like as much is to set the parameters on my story to either exclude or include the properties from the controls.
Primary.parameters = {
controls: {
// either exclude or include
exclude: ['ngAfterContentInit', 'display'],
include: ['percentage', 'error', 'status']
},
}
Describe the bug if component has some properties that are not inputs they are overridden
and template will be
then notInputProperty will be overridden after change detection we will get rendered
``notInputProperty :
.if we add
@Input
decorator to this property then it works as it should and we get rendered: ```notInputProperty : kokos'.setting
angularLegacyRendering: true,
solves the issue.fun fact: after first time storybooks renders You will change the name of property to lets say
notInputProperty2
then it will work! So maybe it has something to do with controls? Restarting storybook (ctr+c) and npm run storybook again will again cause it to be overridden till You again change the name of property to lets saynotInputProperty3
.System