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

UI: Fix conditional hooks usage in sidebar #28979

Merged
merged 3 commits into from
Sep 3, 2024
Merged

UI: Fix conditional hooks usage in sidebar #28979

merged 3 commits into from
Sep 3, 2024

Conversation

JReinhold
Copy link
Contributor

@JReinhold JReinhold commented Aug 27, 2024

What I did

Moved the usage of useStatusSummary() to the top of the Tree component, as React was showing warnings for violating the rules of hooks:

image

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

  1. Compile.
  2. Open a Storybook in development, ie the UI Storybook
  3. Open the browser console
  4. Search for a component in the sidebar
  5. Select the story
  6. Ensure no warnings are logged from React

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/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 PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 76.4 MB 76.4 MB 0 B 0.57 0%
initSize 161 MB 161 MB 309 B -0.98 0%
diffSize 84.8 MB 84.8 MB 309 B -0.98 0%
buildSize 7.48 MB 7.48 MB 8 B 4.35 0%
buildSbAddonsSize 1.62 MB 1.62 MB 0 B 0.74 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 2.31 MB 2.31 MB -4 B 4.36 0%
buildSbPreviewSize 352 kB 352 kB 0 B 0.82 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 4.47 MB 4.47 MB -4 B 4.35 0%
buildPreviewSize 3.01 MB 3.01 MB 12 B 4.33 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 17.6s 20.1s 2.5s 0.5 12.5%
generateTime 22.3s 20.6s -1s -700ms -0.23 -8.2%
initTime 18.1s 17.3s -811ms 0.01 -4.7%
buildTime 13.3s 15s 1.6s 3.18 🔺11.1%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 8.4s 5.9s -2s -486ms -1.91 🔰-41.6%
devManagerResponsive 5.2s 3.7s -1s -511ms -2.4 🔰-40%
devManagerHeaderVisible 883ms 649ms -234ms -1.93 🔰-36.1%
devManagerIndexVisible 921ms 684ms -237ms -1.92 🔰-34.6%
devStoryVisibleUncached 1.7s 1.2s -495ms -0.44 -39.4%
devStoryVisible 920ms 682ms -238ms -1.92 🔰-34.9%
devAutodocsVisible 857ms 642ms -215ms -1.1 -33.5%
devMDXVisible 842ms 641ms -201ms -0.86 -31.4%
buildManagerHeaderVisible 760ms 679ms -81ms -0.93 -11.9%
buildManagerIndexVisible 766ms 680ms -86ms -0.98 -12.6%
buildStoryVisible 837ms 736ms -101ms -0.92 -13.7%
buildAutodocsVisible 652ms 565ms -87ms -2.57 🔰-15.4%
buildMDXVisible 679ms 553ms -126ms -1.68 🔰-22.8%

Greptile Summary

This pull request addresses a React hooks usage issue in the sidebar component of Storybook. Here are the key changes:

  • Moved useStatusSummary() hook to the top level of the Tree component in Tree.tsx
  • Updated StatusContext.tsx to improve type safety
  • Resolved React warnings about violating the rules of hooks
  • Improved code compliance with React best practices

These changes aim to fix conditional hooks usage and eliminate browser console warnings, enhancing the overall stability of the Storybook sidebar component.

@JReinhold JReinhold self-assigned this Aug 27, 2024
@JReinhold JReinhold marked this pull request as ready for review August 27, 2024 12:58
Copy link

nx-cloud bot commented Aug 27, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 9026bd8. 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 target

Sent with 💌 from NxCloud.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

LGTM

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link
Member

@ghengeveld ghengeveld left a comment

Choose a reason for hiding this comment

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

👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants