-
Notifications
You must be signed in to change notification settings - Fork 2k
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 unified-sidebar scrolling #46689
Conversation
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: App Entrypoints (~461 bytes added 📈 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Sections (~83 bytes added 📈 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~52 bytes added 📈 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
I don't think the scroll handler is being cleaned up properly. To test, apply diff: diff --git a/client/my-sites/sidebar-unified/index.jsx b/client/my-sites/sidebar-unified/index.jsx
index 6763389a39..6296943c20 100644
--- a/client/my-sites/sidebar-unified/index.jsx
+++ b/client/my-sites/sidebar-unified/index.jsx
@@ -39,8 +39,10 @@ export const MySitesSidebarUnified = ( { path } ) => {
const sidebarIsCollapsed = useSelector( getSidebarIsCollapsed );
useEffect( () => {
+ console.log( 'Registered event listener' );
window.addEventListener( 'scroll', () => handleScroll() );
return () => {
+ console.log( 'Cleared event listener' );
window.removeEventListener( 'scroll', () => handleScroll() );
};
} );
diff --git a/client/my-sites/sidebar-unified/utils.jsx b/client/my-sites/sidebar-unified/utils.jsx
index 22c82acb7b..bdf43d71f8 100644
--- a/client/my-sites/sidebar-unified/utils.jsx
+++ b/client/my-sites/sidebar-unified/utils.jsx
@@ -6,6 +6,7 @@ let pinnedSidebarBottom = false;
let ticking = false; // Used for Scroll event throttling.
export const handleScroll = () => {
+ console.log( 'handlescroll' );
const windowHeight = window?.innerHeight;
const secondaryElHeight = secondaryEl?.scrollHeight;
const masterbarHeight = document.getElementById( 'header' ).getBoundingClientRect().height;
I think because A and B are different anonymous functions, it can't match them up: useEffect( () => {
window.addEventListener( 'scroll', () => handleScroll() ); // A
return () => {
window.removeEventListener( 'scroll', () => handleScroll() ); // B
};
} ); I'm about to head out, so I haven't tested it, but I think |
From a purely functional perspective this seems to be working fine for me locally until I interact with the My Sites switcher. When scrolling while the site list is showing, it starts detaching the sidebar. Sent you a screen-recording via DM. |
Great finding @mreishus , thanks! Since the callback has no dependencies, declaring |
Thanks @frontdevde for uncovering this! Fixed here 8a74b4c |
8a74b4c
to
493b60c
Compare
Since the changes are regarding the This change also helps |
@@ -78,6 +80,15 @@ class Layout extends Component { | |||
.classList.add( `is-${ this.props.colorSchemePreference }` ); | |||
} | |||
} | |||
if ( config.isEnabled( 'nav-unification' ) ) { | |||
window.addEventListener( 'scroll', scrollCallback ); |
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 this be simplified to the following?
window.addEventListener( 'scroll', scrollCallback ); | |
window.addEventListener( 'scroll', handleScroll ); |
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 was done so that we can effectively clear the event listener as discussed here #46689 (comment). I have already tried using the exported function handleScroll
directly in vain. I may be doing something wrong though..
I'm loving the direction we're going in here. This already feels way better than current Calypso. Scrolling the sidebar by scrolling the page is so much more intuitive than having to scroll inside the sidebar. 👏 Have we tested this on an iPad (in landscape and switching between orientations)? One thing I noticed is that it's still possible to recreate a detached state when using the dev tools. We might need to factor in |
Suggestion: Let's remove the This PR fixes the first part of the issue, which is great! We should definitely limit the scope of this PR to that issue. That said, we'll still need to address the my site switcher overflow being visible during the transition when a site is selected. This will probably involve dynamically hiding the overflow for the duration of the transition. |
I have added the |
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.
After some more testing I can confirm that the resize is now handled well and the previously reported issue is gone.
Let's remove the rouge console.log and then I'd be fine with merging it so we can a) get it in in time for demo and b) you can properly test this on the iPad. Let's keep iterating! 👍
After a lot of try & fail, I eventually:
secondary
area and not the sidebar itself as it is encapsulated over thereChanges proposed in this Pull Request
...props
pass through toSidebar
component.window.addEventListener( 'scroll')
inMySitesSidebarUnified
component so that we reposition (scroll the sidebar) like wp-admin behaves.Testing instructions
?flags=nav-unification
Relates #46643