Skip to content
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

[FIX] Prevent Storybook code-snippet errors crashing the story preview #7874

Conversation

mgadewoll
Copy link
Contributor

Summary

This PR adds an additional try/catch wrapper on the main functionality of the Storybook code-snippet addon to prevent any potential errors in the code snippet from crashing the Storybook preview and making local development impossible. The addon will return no code snippet if an error occurred and log the error to the console.

This does not actually affect any story currently but would be an issue if code is changed/added to a version that the code snippet doesn't support yet. E.g. the functionality to resolve the Emotion css prop is currently not fully supporting all cases, and can break otherwise.

QA

There is not actual way to QA this in the existing Storybook

- ensures code snippet errors don't crash the preview
@mgadewoll mgadewoll added documentation Issues or PRs that only affect documentation - will not need changelog entries skip-changelog labels Jul 4, 2024
@mgadewoll mgadewoll marked this pull request as ready for review July 4, 2024 17:18
@mgadewoll mgadewoll requested a review from a team as a code owner July 4, 2024 17:18
- renames useEffect to useStorybook effect to prevent confusion between React and Javascript context

- removes obsolete useCallback and variable reset
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

import { addons, useEffect, useCallback } from '@storybook/preview-api';
import {
addons,
useEffect as useStorybookEffect,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 Thank you so much for the rename! I totally missed originally that this wasn't actually React's useEffect.

Copy link
Contributor

@cee-chen cee-chen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 This is fantastic! thanks again Lene!

@mgadewoll mgadewoll merged commit a76688b into elastic:main Jul 10, 2024
5 checks passed
@mgadewoll mgadewoll deleted the storybook/prevent-code-snippet-error-crashing-preview branch July 10, 2024 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issues or PRs that only affect documentation - will not need changelog entries skip-changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants