-
Notifications
You must be signed in to change notification settings - Fork 153
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: Empty notifications height #2856
Conversation
]} | ||
/> | ||
); | ||
return <Flashbar items={notifications} />; |
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.
Updated demo implementation to represent real-world use-cases more closely
@@ -167,11 +167,18 @@ describe.each(['classic', 'refresh', 'refresh-toolbar'] as Theme[])('%s', theme | |||
test( | |||
'does not render notifications slot when it is empty', |
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.
We already had a test which was supposed to catch the issue, but it was asserting size of the wrong element. Refactored the test. It is now more strict and may require an update even on unrelated design changes, but this is still better than silently passing
@@ -23,8 +24,9 @@ export function AppLayoutNotificationsImplementation({ | |||
children, | |||
}: AppLayoutNotificationsImplementationProps) { | |||
const { ariaLabels, stickyNotifications, setNotificationsHeight, verticalOffsets } = appLayoutInternals; | |||
const ref = useRef<HTMLElement>(null); | |||
useResizeObserver(ref, entry => setNotificationsHeight(entry.borderBoxHeight)); | |||
const [hasNotificationsContent, contentRef] = useContainerQuery(rect => rect.borderBoxHeight > 0); |
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.
an extra resize observer may seem like a waste, but it allows us to resolve this rendering logic without talking outside this component, which is useful in the widget environment (compatibility with existing code)
361636e
to
936684e
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2856 +/- ##
==========================================
- Coverage 96.20% 96.19% -0.01%
==========================================
Files 761 761
Lines 21436 21438 +2
Branches 6939 7327 +388
==========================================
Hits 20622 20622
+ Misses 806 763 -43
- Partials 8 53 +45 ☔ View full report in Codecov by Sentry. |
return null; | ||
const notifications: Array<FlashbarProps.MessageDefinition> = []; | ||
if (visible) { | ||
notifications.push({ |
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.
Why do you push an element to the array on the rendering condition? Why not directly provide an array with a single item based on visible
? At least it would be more readable
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.
Do you want something like this
return <Flashbar items={visible ? [demoNotification] : []}>
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.
yes
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.
Done
14de51b
to
82e17e3
Compare
82e17e3
to
92c4e40
Compare
@@ -167,11 +167,19 @@ describe.each(['classic', 'refresh', 'refresh-toolbar'] as Theme[])('%s', theme | |||
test( | |||
'does not render notifications slot when it is empty', | |||
setupTest({ pageName: 'with-notifications' }, async page => { | |||
const { height: originalHeight } = await page.getBoundingBox(wrapper.findNotifications().toSelector()); | |||
expect(originalHeight).toBeGreaterThan(0); | |||
const { height: headerHeight } = await page.getBoundingBox('#h'); |
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.
This height is different between CI and my local. I got it working when reading this value dynamically
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.
Could you elaborate what is "dynamic" in this code? And why the height is different in different environments?
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.
The header height depends on system font rendering which is not deterministic and varies between Mac/Linux.
Tried to make it more deterministic: 14de51b
It broke other tests, so I abandoned this path
@@ -167,11 +167,19 @@ describe.each(['classic', 'refresh', 'refresh-toolbar'] as Theme[])('%s', theme | |||
test( | |||
'does not render notifications slot when it is empty', | |||
setupTest({ pageName: 'with-notifications' }, async page => { | |||
const { height: originalHeight } = await page.getBoundingBox(wrapper.findNotifications().toSelector()); | |||
expect(originalHeight).toBeGreaterThan(0); | |||
const { height: headerHeight } = await page.getBoundingBox('#h'); |
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.
Could you elaborate what is "dynamic" in this code? And why the height is different in different environments?
refresh: headerHeight + 12, | ||
'refresh-toolbar': headerHeight + 54, | ||
}[theme]; | ||
expect(contentTop).toEqual(expectedOffset); |
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.
Isn't it be easier to only check notification container height and make sure it equals 0?
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.
This is how original test was structured and it still allowed this regression to happen.
The new approach makes sure this test fails every time there is an extended top offset of the main content, regardless how it is implemented internally
92c4e40
to
c07c3ef
Compare
Description
Widget friendly version of #2810. Thanks @georgylobko for the original code.
See inline comments for more details
Related links, issue #, if available: n/a
How has this been tested?
Review checklist
The following items are to be evaluated by the author(s) and the reviewer(s).
Correctness
CONTRIBUTING.md
.CONTRIBUTING.md
.Security
checkSafeUrl
function.Testing
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.