-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Svelte: Fix events not being logged in Actions when a story has decorators #28247
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit de8c666. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
let instance; | ||
let decoratorInstance; |
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.
What are those 2 variables doing? I don't see them anywhere set in the codebase.
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.
They are set in the markup below in the file, and read on line 39.
They are used to listen to events from the instances.
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.
ah, I see, it is like a react ref?
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.
Maybe you're confusing them for props? They aren't exported so they aren't props, they are just regular variables.
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.
I mean it is like:
const instance = useRef();
<div ref={instance} />
In react?
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 you could compare it to a ref, it's just a regular long-living variable.
(my previous message wasn't a response to your react message, we basically posted them at the same time)
Looking more into the svelte code. Shouldn't this line be in the SlotDecorator instead? storybook/code/renderers/svelte/src/components/PreviewRender.svelte Lines 47 to 56 in 595a08c
Normally the component here is the |
Object.entries(on).forEach(([eventName, eventCallback]) => { | ||
// instance can be undefined if a decorator doesn't have <slot/> | ||
Object.entries({ ...eventsFromArgTypes, ...on }).forEach(([eventName, eventCallback]) => { | ||
// instance can be undefined if a decorator doesn't have a <slot/> |
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.
// instance can be undefined if a decorator doesn't have a
shouldn't that be an error though?
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.
That's debatable, I guess it's similar to not calling storyFn()
in a React decorator, to not render the actual story. Would that be invalid? 🤷
You are right! I tried that, but it's not as easy as I thought with our current data structure. Only the In fact it's also guarding against a very rare case, because we're setting storybook/code/renderers/svelte/src/decorators.ts Lines 44 to 58 in 6dea5b0
The only way I could reach the error was by not setting I vote leave as-is, the trade off is not there right now. |
@@ -15,6 +15,8 @@ | |||
props = {}, | |||
/** @type {{[string]: () => {}}} Attach svelte event handlers */ | |||
on, | |||
/** @type {any} whether this level of the decorator chain is the last, ie. the actual story */ |
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.
This comment seems incorrect.
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.
LGTM
Closes #20690
What I did
SlotDecorator
component instead of passing it down via props. As [Bug]: Decorators in Svelte causes dispatched events to not be logged in Actions #20690 (comment) correctly points out,SlotDecorator
didn't correctly pass that prop down to nestedSlotDecorator
's. Avoiding prop drilling was just easierPreviewRender
component down to the inner-mostSlotDecorator
. Only that lastSlotDecorator
can actually attach the event listeners to the original story.PreviewRender
now passesargTypes
down via a context.Note that there's a weird bug where actions are logged correctly, until you navigate to a story of another component, then all actions will be logged twice, once as
click
and then asevent_click
. I have no idea why this happens, I tried to figure it out but couldn't, and it happened before this PR as well, so at least it's not a regression because of this.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
/?path=/story/stories-renderers-svelte-slot-decorators--with-default-red-border
(this story has decorators)next
sandbox does not log actions, even though it should. https://6308736456ad2046275c0ae7-bczjhlhvbw.chromatic.com/?path=/story/stories-renderers-svelte-slot-decorators--with-default-red-borderDocumentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
This pull request has been released as version
0.0.0-pr-28247-sha-834d31db
. Try it out in a new sandbox by runningnpx [email protected] sandbox
or in an existing project withnpx [email protected] upgrade
.More information
0.0.0-pr-28247-sha-834d31db
jeppe/fix-svelte-decorator-actions
834d31db
1718404452
)To request a new release of this pull request, mention the
@storybookjs/core
team.core team members can create a new canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=28247