-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Core: Fix scrollIntoView
behavior and reimplement testing module time rendering
#30044
Conversation
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.
4 file(s) reviewed, 9 comment(s)
Edit PR Review Bot Settings | Greptile
export const JustNow: Story = { | ||
args: { | ||
timestamp: new Date(), | ||
}, | ||
}; |
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.
logic: using new Date() will cause this story to show different results each time it's rendered, making visual regression testing unreliable
const meta = { | ||
component: RelativeTime, | ||
args: { | ||
testCount: 42, |
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.
style: testCount of 42 seems arbitrary - consider using a more meaningful default that demonstrates singular/plural handling
'month', | ||
'year', | ||
]; | ||
const seconds = Math.round((Date.now() - date.getTime()) / 1000); |
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.
logic: This calculation assumes the timestamp is in the past - future dates will show incorrect values
} | ||
|
||
const days = Math.floor(hours / 24); | ||
return days === 1 ? 'yesterday' : `${days} days ago`; | ||
} | ||
|
||
export const RelativeTime = ({ timestamp, testCount }: { timestamp: Date; testCount: number }) => { | ||
const [relativeTimeString, setRelativeTimeString] = useState(null); |
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.
style: useState should specify type: useState<string | null>(null)
if (!top || !bottom) { | ||
return; | ||
} |
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.
logic: this null check is redundant since getBoundingClientRect() always returns a DOMRect with numeric values
const { containerRef, center = false, attempts = 3, delay = 500 } = options; | ||
const element = (containerRef ? containerRef.current : document)?.querySelector(selector); |
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.
logic: optional chaining here could cause element to be undefined even when containerRef.current exists, if querySelector returns null
const bottomOffset = | ||
document?.querySelector('#sidebar-bottom-wrapper')?.getBoundingClientRect().top || | ||
globalWindow.innerHeight || | ||
document.documentElement.clientHeight; |
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.
style: consider caching bottomOffset value to avoid repeated DOM queries and reflows
} else if (_attempt <= attempts) { | ||
setTimeout(scrollToSelector, delay, selector, options, _attempt + 1); | ||
} |
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.
logic: recursive setTimeout calls could stack up if the selector matches multiple times during retries
if (bottom > bottomOffset) { | ||
element.scrollIntoView({ block: center ? 'center' : 'nearest' }); | ||
} |
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.
logic: element may still be partially hidden if top < 0. Should also check if top is above viewport
☁️ Nx Cloud ReportCI is running/has finished running commands for commit f88023a. 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. |
Package BenchmarksCommit: The following packages have significant changes to their size or dependencies:
|
Before | After | Difference | |
---|---|---|---|
Dependency count | 59 | 59 | 0 |
Self size | 411 KB | 45 KB | 🎉 -366 KB 🎉 |
Dependency size | 13.46 MB | 13.46 MB | 0 B |
Bundle Size Analyzer | Link | Link |
@storybook/addon-onboarding
Before | After | Difference | |
---|---|---|---|
Dependency count | 0 | 2 | 🚨 +2 🚨 |
Self size | 235 KB | 216 KB | 🎉 -19 KB 🎉 |
Dependency size | 670 B | 235 KB | 🚨 +235 KB 🚨 |
Bundle Size Analyzer | Link | Link |
@storybook/experimental-addon-test
Before | After | Difference | |
---|---|---|---|
Dependency count | 60 | 60 | 0 |
Self size | 972 KB | 958 KB | 🎉 -15 KB 🎉 |
Dependency size | 14.14 MB | 14.14 MB | 0 B |
Bundle Size Analyzer | Link | Link |
@storybook/core
Before | After | Difference | |
---|---|---|---|
Dependency count | 49 | 50 | 🚨 +1 🚨 |
Self size | 21.44 MB | 21.44 MB | 🚨 +237 B 🚨 |
Dependency size | 14.34 MB | 14.36 MB | 🚨 +16 KB 🚨 |
Bundle Size Analyzer | Link | Link |
@storybook/experimental-nextjs-vite
Before | After | Difference | |
---|---|---|---|
Dependency count | 153 | 87 | 🎉 -66 🎉 |
Self size | 231 KB | 231 KB | 🎉 -152 B 🎉 |
Dependency size | 44.67 MB | 31.57 MB | 🎉 -13.10 MB 🎉 |
Bundle Size Analyzer | Link | Link |
storybook
Before | After | Difference | |
---|---|---|---|
Dependency count | 50 | 51 | 🚨 +1 🚨 |
Self size | 22 KB | 22 KB | 0 B |
Dependency size | 35.78 MB | 35.79 MB | 🚨 +16 KB 🚨 |
Bundle Size Analyzer | Link | Link |
sb
Before | After | Difference | |
---|---|---|---|
Dependency count | 51 | 52 | 🚨 +1 🚨 |
Self size | 1 KB | 1 KB | 0 B |
Dependency size | 35.80 MB | 35.82 MB | 🚨 +16 KB 🚨 |
Bundle Size Analyzer | Link | Link |
@storybook/cli
Before | After | Difference | |
---|---|---|---|
Dependency count | 392 | 393 | 🚨 +1 🚨 |
Self size | 493 KB | 493 KB | 0 B |
Dependency size | 77.38 MB | 77.40 MB | 🚨 +16 KB 🚨 |
Bundle Size Analyzer | Link | Link |
@storybook/codemod
Before | After | Difference | |
---|---|---|---|
Dependency count | 272 | 273 | 🚨 +1 🚨 |
Self size | 612 KB | 612 KB | 0 B |
Dependency size | 67.38 MB | 67.39 MB | 🚨 +16 KB 🚨 |
Bundle Size Analyzer | Link | Link |
create-storybook
Before | After | Difference | |
---|---|---|---|
Dependency count | 108 | 109 | 🚨 +1 🚨 |
Self size | 1.11 MB | 1.11 MB | 0 B |
Dependency size | 44.91 MB | 44.93 MB | 🚨 +16 KB 🚨 |
Bundle Size Analyzer | Link | Link |
What I did
Updated the sidebar's
scrollIntoView
behavior to make the selected story visible when switching stories. It wasn't taking into account the testing module which may overlap the selected story, and wasn't triggering after creating a new story file through the UI.Updated the RelativeTime logic to be more concise, less technical and more fitting to our use case. I didn't shorten "seconds" or "minutes" to "s" or "m" but instead made it less likely for those to show up.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
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-storybook/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-30044-sha-f88023ad
. 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-30044-sha-f88023ad
ui-fixes
f88023ad
1734080701
)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=30044
Greptile Summary
Improved sidebar scroll behavior and simplified the RelativeTime component's implementation for the testing module, focusing on better visibility and user-friendly time displays.
code/core/src/manager/utils/tree.ts
to check for testing module overlap when scrolling stories into viewcode/core/src/manager/components/sidebar/useHighlighted.ts
for more reliable story scrollingcode/addons/test/src/components/RelativeTime.tsx
to use direct time calculations instead of Intl.RelativeTimeFormatRelativeTime.stories.tsx
for various time intervals