Conversation
…g-the-reset-controls-button-appears-to-be-resetting-the-value-back-to-undefined
| * We listen for the RESET_STORY_ARGS event and store the storyId to be reset | ||
| * We then use this in the renderToCanvas function to force remount the story | ||
| */ | ||
| const storyIdsToRemountFromResetArgsEvent = new Set<string>(); |
There was a problem hiding this comment.
I'm unsure if this Set would ever have more than one entry at a time. It would only occur if RESET_STORY_ARGS were sent for multiple stories at the same time, and their renderToCanvas were all called after them (because renderToCanvas immediately removes the story id from the Set again).
I can't think of a scenario where that would happen - in that sense this could be simplified to be a single string instead of a Set.
However this feels more bulletproof in a way.
| await within(canvasElement).findByText(/New Text/); | ||
| await expect(button).toHaveFocus(); | ||
|
|
||
| await channel.emit(RESET_STORY_ARGS, { storyId: id }); |
There was a problem hiding this comment.
resetting args at the end of this test is unnecessary, because we recently added logic to reset args at the beginning also - both as a way to ensure that the story is in a clean state before executing.
tmeasday
left a comment
There was a problem hiding this comment.
LGTM @JReinhold 👏
In 7.1 we should probably add information about whether this is a "reset" to the renderToCanvas call (IIRC that's the plan right?)
Do you have thoughts about the individual arg reset issue? Is this something that can realistically happen to a component? If not, should we just be resetting in the same way?
| * We listen for the RESET_STORY_ARGS event and store the storyId to be reset | ||
| * We then use this in the renderToCanvas function to force remount the story | ||
| */ | ||
| const storyIdsToRemountFromResetArgsEvent = new Set<string>(); |
Yes, tracking in #21706
I actually think we should keep it as-is for now. Reseting an individual arg is synonymous with changing the prop to |
…g-the-reset-controls-button-appears-to-be-resetting-the-value-back-to-undefined
…g-the-reset-controls-button-appears-to-be-resetting-the-value-back-to-undefined
Closes #21470
What I did
This PR makes the Svelte renderer force remount the story when a user resets all args in the controls panel.
It does this by listening for the
RESET_STORY_ARGSevent, saves the information that a story is being reset, and uses that information inrenderToCanvasto remount instead of just updating props.There's a possible race condition here, because the
RESET_STORY_ARGSevent will both trigger this custom listener and also triggerrenderToCanvas. If for some reasonrenderToCanvasreacts to the event before the custom listener, then it won't know that it should remount, and it will most likely remount on the following render, eg. triggered by a regular arg change.I've been unable to produce this out-of-order triggering so for now it's purely theoretical.
There's still an issue here though, that when any singular control gets unset, that will not cause a full remount and the component will not revert to default but rather act as if the value was
undefined. From a purely Svelte-rendering perspective this is expected, the same thing happens if your Svelte components do that (set a prop to something and then sets it toundefined). But maybe from a Storybook user perspective this is unexpected, at least I would expect it to go back to the default.This scenario is only valid for the color control as it is the only control that can be unset. But I suspect we'll make this a universal feature in the future.
How to test
nextbranch and see that the button loses its size completely becausesizebecomesundefined.Checklist
MIGRATION.MD
Maintainers
make sure to add the
ci:mergedorci:dailyGH label to it.["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]