-
-
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
Core: Story context is prepared before for supporting fine grained updates #20755
Core: Story context is prepared before for supporting fine grained updates #20755
Conversation
I don't know why snapshots didn't report for you, I just did |
@webblocksapp could you add an entry to the |
@JReinhold updated |
Thxs for the clarification, it was my bad. I was running -u in the wrong test. |
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.
We'll also need to update this function to prepare the context:
storybook/code/lib/preview-api/src/modules/store/csf/testing-utils/index.ts
Lines 75 to 84 in 2cceaad
const composedStory = (extraArgs: Partial<TArgs>) => { | |
const context: Partial<StoryContext> = { | |
...story, | |
hooks: new HooksContext(), | |
globals: defaultGlobals, | |
args: { ...story.initialArgs, ...extraArgs }, | |
}; | |
return story.unboundStoryFn(context as StoryContext); | |
}; |
code/lib/preview-api/src/modules/preview-web/render/StoryRender.ts
Outdated
Show resolved
Hide resolved
@webblocksapp thanks very much, can I ask for one more thing -- now the arg mapping crosses the module boundary between Maybe we can simply modify this test to add a mapping?
|
@tmeasday - Added integration tests. This modification affected an average of 34 tests at |
It looks like the e2e tests for Actions are failing in this PR. I've investigated a bit and confirmed locally that the button indeed does not log any actions when clicked, which it should. I'll continue investigating where it breaks when I can. |
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.
Thanks for tweaking the tests!
@JReinhold confirmed, actions are broken. Inspecting the console gives the following error when clicking the blue button inside the button story.
Let me know if you have any clue about this. From my side, tomorrow I will also continue checking the issue. |
I tracked down the issue, and pushed a fixed (at least it worked locally). Basically, when an action event is triggered, it is serialized (stringified) so it can be emitted over the channel. Stringification breaks if there are circular structures, which is what happened here. There has always been a circular structure in React Synthetic events, however our stringifier defaults to stop stringifying when it reaches a depth 15. The highest depth that can now be used while still not crashing is depth 11, which I've changed the default to (it's However why this PR requires the change, I don't know. My only idea is that maybe our previous arg mapping would make the event uncircular because of how we did object assigning, and now that the args are more "pure", the circular structure remains at the time of serialization. Maybe not, maybe @tmeasday knows. |
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.
💪
@JReinhold is the circular object in the args? Looking at the preview-web tests we don't ever send the mapped args over the channel (good!), so it would be surprising if so. If not, it's weird that this issue has just started in this PR. |
I was checking @JReinhold changes, so the issue was at |
Yeah, that's right. It is a (edge casey) bug in telejson: storybookjs/telejson#93 It sort of makes sense why this PR triggered it, but we didn't trace down the exact reasons. Basically the
Targetted args is an undocumented feature that we added to allow experimentation. We haven't really developed the concept yet but you can read about it here: https://chromatic-ui.notion.site/Args-for-side-loaded-data-6ba311ecc1c7447197e0cbf404dd3dbf The choice to use |
…context-at-story-render
It's awesome! I'm excited to see this PR was merged. Thxs a lot for your great support to help me make this contribution a reality. It was a pleasure to work with you @JReinhold, @tmeasday and the Storybook team. With this, I will start next week working on the organization repo with the SolidJS renderer and framework. |
Great! I'm eager to assist you with anything you need going forward, let's make this a kick-ass integration. I'll close the feedback PR now. |
Issue: #20584
What I did
I needed to make some changes to how we prepare stories, in order to make args reactive in frameworks that use reactive proxies such as SolidJS or Vue for fine-grained updates.
This change modifies the way Storybook currently prepares stories which causes reactive args to get lost for fine-grained updates JS frameworks. That's because for those frameworks handle args/props as proxies behind the scenes to make reactivity work. So when we do the
argType
mapping inprepareStory
the Proxies are destroyed and args becomes a plain object again, losing the reactivity.The proposal here is to change the flow, passing the mapped args at
renderToCanvas
so that the proxies stay intact.There's a chance that this change will also make reactive args in Vue3 possible, something that we currently can't do without re-creating the whole Vue story.
How to test
yarn task --task sandbox --start-from auto --template react-vite/default-ts
@tmeasday - It was added a test at
prepareStory.test.ts
to confirm that prepared args are received on each decorator.Checklist
MIGRATION.MD
Maintainers
make sure to add the
ci:merged
orci:daily
GH label to it.["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]