-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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: useTruncation infinite loop, reenable dashboard cross links on ChartList #27701
fix: useTruncation infinite loop, reenable dashboard cross links on ChartList #27701
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #27701 +/- ##
==========================================
+ Coverage 69.78% 69.79% +0.01%
==========================================
Files 1911 1914 +3
Lines 75024 75103 +79
Branches 8355 8390 +35
==========================================
+ Hits 52352 52415 +63
- Misses 20622 20624 +2
- Partials 2050 2064 +14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
e9830f9
to
08827ca
Compare
@@ -157,6 +157,20 @@ const StyledActions = styled.div` | |||
color: ${({ theme }) => theme.colors.grayscale.base}; | |||
`; | |||
|
|||
const DashboardCrossLinks = React.memo( |
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.
It appears to be more beneficial to create a dedicated file specifically for this component.
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.
Agreed 👍
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
49f24f0
to
62932b3
Compare
@justinpark would you be able to do another pass? |
/testenv up |
@kgabryje Ephemeral environment spinning up at http://34.220.216.100:8080. Credentials are |
// "..." is around 6px wide | ||
const truncationWidth = 6; |
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.
I thought we had a function for computing the width of a given element? Can we use something like element.getBoundingClientRect().width
to get the exact width of the ellipsis rendered in an invisible element?
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.
Not really - the ellipsis is not something that we can grab, because it's not an element in the DOM. What we could do to get a more precise measurement is render <span>...</span>
somewhere off screen, measure the width, remove that element and use that width here.
To be honest I'm not sure if it's worth it, the worst thing that can happen here is an off-by-one error in some edge cases
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.
return () => { | ||
obs.disconnect(); | ||
}; |
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.
return () => { | |
obs.disconnect(); | |
}; | |
return obs.disconnect; |
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.
Oh good point! Though to be fair, I’m not sure about readability - I was halfway through writing a comment about how we should return a cleanup function rather than returning obs.disconnect()
… but it’s early morning, so maybe it’s my fault 😉
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.
I'm almost 50-50 here, but I'm leaning in the direction of @betodealmeida here, so I'd say +1 for changing to return obs.disconnect;
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.
2 vs 1, request for change has passed 🙂
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.
@villebro @betodealmeida With return obs.disconnect
, the page is crashing with illegal invocation
error. To be honest I don't know why it doesn't work, but it does work with return () => { obs.disconnect(); }
so I'm going with that
@@ -31,8 +31,7 @@ export const NameRow = ({ | |||
hidePopover, | |||
}: FilterCardRowProps & { hidePopover: () => void }) => { | |||
const theme = useTheme(); | |||
const filterNameRef = useRef<HTMLElement>(null); | |||
const [elementsTruncated] = useTruncation(filterNameRef); | |||
const [filterNameRef, , elementsTruncated] = useTruncation(); |
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.
#TIL
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.
In addition to the fix, very nice cleanup work here 👍 A non-blocking comment on the column name + supporting Beto's change request.
return () => { | ||
obs.disconnect(); | ||
}; |
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.
I'm almost 50-50 here, but I'm leaning in the direction of @betodealmeida here, so I'd say +1 for changing to return obs.disconnect;
cy.getBySel('sort-header').eq(4).contains('Owners'); | ||
cy.getBySel('sort-header').eq(5).contains('Last modified'); | ||
cy.getBySel('sort-header').eq(6).contains('Actions'); | ||
cy.getBySel('sort-header').eq(4).contains('Dashboards added to'); |
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 maybe out of scope, but I feel Dashboards added to
is too verbose, and I think just going with Dashboards
or On dashboards
makes more sense.
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.
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.
@kasiazjc says that "On dashboards" sounds fine. I changed it here (in charts list) and also in Explore for consistence
Ephemeral environment shutdown and build artifacts deleted. |
SUMMARY
Due to a bug in
useChildElementTruncation
, there was an edge case which could trigger an infinite loop of rerenders. The bug occurs when the difference in width of subsequent numbers after the plus sign (e.g. +4 and +5) is just big enough to change the truncation state to the other number. This PR ensures that the calculation is performed only once, and if the edge case is triggered, we simply accept the off-by-one error.This PR also implements a ResizeObserver which recalculates the truncations if the container size changes. Previously we relied on the width values from references in
useLayoutEffect
's dependency array, which was not a correct approach, since the changes of those values would not trigger a rerender.This change allowed us to bring back the feature that relied on the truncation logic, which is dashboard cross links on Chart List page. The feature adds a column to the list which displays the dashboards that given chart is added to.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before (occurred long ago when "dashboards added to" column was not yet hidden):
After:
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION