-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
core: add Stack and Separator component #97052
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
Conversation
core: add separator component core: add core separator core: add separator
query: window.matchMedia(`(min-width: ${theme.breakpoints[bp]})`), | ||
}); |
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.
Potential bug: The `useResponsivePropValue` hook accesses `window.matchMedia` without a safety check, which will cause a crash during server-side rendering (SSR).
- Description: The
useResponsivePropValue
hook directly callswindow.matchMedia
during component initialization. In a server-side rendering (SSR) environment, where thewindow
object is not available, this will throw aReferenceError: window is not defined
. This error will cause the server rendering process to crash whenever a component using this hook, such asStack
, is rendered. Other parts of the codebase already use safe access patterns liketypeof window !== 'undefined'
or optional chaining (window.matchMedia?.()
), which this new code fails to implement. - Suggested fix: Add a check to ensure
window
is defined before callingwindow.matchMedia
. Use optional chaining (window.matchMedia?.()
) or a condition liketypeof window !== 'undefined'
. The hook should return a default orundefined
value during server-side rendering to prevent the crash.
severity: 0.9, confidence: 0.95
Did we get this right? 👍 / 👎 to inform future reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #97052 +/- ##
=======================================
Coverage 80.67% 80.67%
=======================================
Files 8549 8549
Lines 376208 376208
Branches 24443 24443
=======================================
Hits 303503 303503
Misses 72333 72333
Partials 372 372 |
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.
looks great 🔥
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.
Bug: Responsive Prop Handling Mismatch
The getOrientationFromDirection
function has a type mismatch: it expects the raw StackLayoutProps['direction']
(which can include responsive objects), but it's called with the resolved string value from useResponsivePropValue
. Additionally, useResponsivePropValue
can return undefined
if all responsive breakpoints are undefined
(e.g., direction={{sm: undefined}}
). Passing this undefined
value to getOrientationFromDirection
results in a TypeError
with the message "No Stack Direction was provided".
static/app/components/core/layout/stack.tsx#L153-L196
static/app/components/core/layout/stack.tsx#L40-L42
sentry/static/app/components/core/layout/stack.tsx
Lines 40 to 42 in 2f51328
function getOrientationFromDirection( | |
direction: NonNullable<StackLayoutProps['direction']> |
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.
nice 🙌
Adds a Stack and Separator component. The Stack.Separator is essentially just a wrapper around the Separator that omits the orientation prop. We want to do this to avoid possible user error where they would end up displaying a horizontal separator in a horizontal row. The orientation management is handled via OrientationContext from inside the Stack Component. An alternative could have been to use cloneElement with a bit of detection for the Separator element and provide the prop, but I think context is fine given that the context consumer is scoped to the Stack.Separator component.
Adds a Stack and Separator component.
The Stack.Separator is essentially just a wrapper around the Separator that omits the orientation prop. We want to do this to avoid possible user error where they would end up displaying a horizontal separator in a horizontal row.
The orientation management is handled via OrientationContext from inside the Stack Component. An alternative could have been to use cloneElement with a bit of detection for the Separator element and provide the prop, but I think context is fine given that the context consumer is scoped to the Stack.Separator component.