spectrum-css
spectrum-css copied to clipboard
fix: chromatic testing preview refresh issue and docs exception
Description
Storybook: fixes the refresh issue with the chromatic testing preview toolbar item, and excludes Chromatic-only templates from the autodocs
Previously when the Chromatic "view testing preview" toolbar item was used, the story would not refresh and display the correct templates until the browser was hard refreshed.
This appears to be partly because the custom window.isChromatic function was not working with the dynamic global values (globals.testingPreview).
This update makes sure that when the decorator is run, it's working with the current value of globals.testingPreview
. It also passes through a boolean isChromaticView
to the story args, which should remove the need to use the window object.
The window.isChromatic()
function is left in for the time being for backwards compatibility and consideration of current migrations, but can be refactored away (noted in a @todo
comment). For this PR I updated Action button and Pagination as an example of this. I could go through and modify all usage of window.isChromatic()
as part of this PR if desired; I limited the scope of this in order to get feedback on this first.
✨ The function also now excludes Chromatic-only templates from the Docs / autodocs pages by adding a check against context.viewMode
.
CSS-832
How and where has this been tested?
Please tag yourself on the tests you've marked complete to confirm the tests have been run by someone other than the author.
Validation steps
- [ ] Toolbar item in Storybook to view the Chromatic templates ("Show testing preview" and "Default mode") will now refresh the story when it is used. Without a browser refresh.
- [ ] Chromatic-only templates are not appearing on the docs / autodocs pages (whether "show testing preview" is active or inactive).
- [ ] Chromatic-only and regular templates are working correctly for Action button and Pagination (which now access
args.isChromaticView
) - [ ] Chromatic-only and regular templates are working correctly for other components. Please go through and test a bunch of other components.
- [ ] VRT is working normally. There are no VRT changes from this PR.
Regression testing
Validate:
- The documentation pages for at least two other components are still loading, including:
- [ ] The pages render correctly, are accessible, and are responsive.
- If components have been modified, VRTs have been run on this branch:
- [ ] VRTs have been run and looked at.
- [ ] Any VRT changes have been accepted (by reviewer and/or PR author), or there are no changes.
To-do list
- [x] I have read the contribution guidelines.
- [x] I have updated relevant storybook stories and templates.
- [ ] If my change impacts other components, I have tested to make sure they don't break.
- [ ] If my change impacts documentation, I have updated the documentation accordingly.
- [ ] ✨ This pull request is ready to merge. ✨