Skip to content
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

[feedback-widget] feat: lazy load feedback widget component #13616

Closed
wants to merge 18 commits into from

Conversation

pieh
Copy link
Contributor

@pieh pieh commented Apr 25, 2019

This is PR against #13550

After running webpagetest:

first interactive seems significantly faster on lazy loaded one and feedback component isn't critical to be immediately shown on initial mount / page transition so I think tradeoff of (slightly) delaying it in favour of faster overall interactivity seems good idea

Preview for this version available at https://5cc0c487ba5e4e79a0a62cf8--gatsby-org-pieh-previews.netlify.com/docs/

@pieh pieh requested a review from a team as a code owner April 25, 2019 00:11
KyleAMathews
KyleAMathews previously approved these changes Apr 25, 2019
@KyleAMathews
Copy link
Contributor

Could we lazy load it on hover or click?

@KyleAMathews
Copy link
Contributor

onMouseOver actually?

@pieh
Copy link
Contributor Author

pieh commented Apr 25, 2019

Could we lazy load it on hover or click?
onMouseOver actually?

Sure, would require some reorganization (as we would want to show button always) and start lazy loading on hover (and focus :) ). Probably would also need some extra handling to queue click events if it wan't loaded yet to not have glitchy experience

@pieh
Copy link
Contributor Author

pieh commented Apr 25, 2019

I can address this tomorrow

@pieh
Copy link
Contributor Author

pieh commented Apr 25, 2019

Preview link after addressing lazy loading on hover/focus - https://5cc1c705443c86d19f93cd46--gatsby-org-pieh-previews.netlify.com/docs/

@pieh
Copy link
Contributor Author

pieh commented Apr 25, 2019

Here's preview of it - lazy loading starts when button is hovered or focused

Kapture 2019-04-25 at 21 02 57

On slow connection (as shown with emulated 2g connection above) it could be useful to indicate somehow that something is happening (if after clicking the button widget doesn't load in 500-1000ms)

@KyleAMathews
Copy link
Contributor

Maybe use intersection observer then? A little more head start. It's 23kb so not that much code.

@KyleAMathews
Copy link
Contributor

The animations are great btw 😍

@pieh
Copy link
Contributor Author

pieh commented Apr 25, 2019

The animations are great btw 😍

All hail @greglobinski ! :)

Maybe use intersection observer then? A little more head start. It's 23kb so not that much code.

Would you want to show button before we load full widget? Because if yes, then we will still have same problem on slower connection - user can click button before widget is ready to be used. If we don't show button, then there would be this weird (IMO) interaction on mobile, when you scroll to the bottom, suddenly button would "randomly" show up (on desktop button is fixed in viewport)

@pieh
Copy link
Contributor Author

pieh commented Apr 25, 2019

In any case - I'll try to repurpose the "working" spinning icon that is used when submitting feedback

@wardpeet
Copy link
Contributor

Because the button has a scale, the svg is pretty blurry when transitioning, it also isn't super fluent better to set the width & height of the button to the correct value and scale down instead of scaling up. 🙈

Perhaps add a spinner to the button or set the button to disabled to show that something is happening. We could also leverage suspense for this to only show this when it's taking long.

@marcysutton
Copy link
Contributor

In testing the preview link with the keyboard and Voiceover, I can't seem to trigger the feedback widget to open with the space or enter keys.

There is also no visible focus style–possibly because of the display: flex on the button? I'm not quite sure.

@pieh
Copy link
Contributor Author

pieh commented Apr 25, 2019

Because the button has a scale, the svg is pretty blurry when transitioning, it also isn't super fluent better to set the width & height of the button to the correct value and scale down instead of scaling up. 🙈

(I think) I didn't change anything related to styling (other than moving few things around), so this potentially would need to be mentioned in main PR - #13550

Perhaps add a spinner to the button or set the button to disabled to show that something is happening. We could also leverage suspense for this to only show this when it's taking long.

I don't want to "disable" button, as it would loose focusability (I think). Suspense I think is problematic right now for us (SSR), but I can implement this by hand.

In testing the preview link with the keyboard and Voiceover, I can't seem to trigger the feedback widget to open with the space or enter keys.

There is also no visible focus style–possibly because of the display: flex on the button? I'm not quite sure.

What browser were You using? It seems to work on Chrome for me (both navigation / toggling widget with space/enter and visible focus), but I want to take another look if I can reproduce this

@marcysutton
Copy link
Contributor

marcysutton commented Apr 25, 2019

What browser were You using?

I used Safari and Chrome. It doesn't work for me in either, even without Voiceover on.

@greglobinski
Copy link
Contributor

It seems to work on Chrome for me (both navigation / toggling widget with space/enter and visible focus)

For me too, also on FF (Ubuntu)

I used Safari and Chrome. It doesn't work for me in either,

@marcysutton Did it work for you before?

@greglobinski
Copy link
Contributor

greglobinski commented Apr 26, 2019

the svg is pretty blurry when transitioning,

@wardpeet Are you pointing the hover rotating transition of the "close-X" icon? I will fix that, thanks.

@pieh
Copy link
Contributor Author

pieh commented Apr 26, 2019

What browser were You using? It seems to work on Chrome for me (both navigation / toggling widget with space/enter and visible focus), but I want to take another look if I can reproduce this

I was able to reproduce this in Safari. This happens because the initial button is removed once full widget loads, and focus is not being transferred to toggle button from full widget. It's pretty tough tho, because re-focusing button has visible drop-down animation (suddenly orange "outline" disappear and is animated back in).

I hoped using same ref would prevent that, but it doesn't and this is result of react diffing algorithm. TBD what's best way to solve this - either prevent focus outline animation on initial widget render or hoist the button totally, so it never change location in component tree.

@pieh
Copy link
Contributor Author

pieh commented May 2, 2019

I forgot to add preview for latest version of it - https://5cc73d8862760198feb5f6c5--gatsby-org-pieh-previews.netlify.com/docs/

It should also fix focus/hover box shadow on toggle button in Safari

Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greglobinski yes indeed :)

@pieh looks good. I would keep the focus inside the feedback widget until closed but that's another PR :)

}
return state
})
}, 1000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

following rail practices https://developers.google.com/web/fundamentals/performance/rail this should be 100ms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong opinion on this (but I think 100ms might be to short?) - I've used timeout we use already in core

// Start a timer to wait for a second before transitioning and showing a
// loader in case resources aren't around yet.
const timeoutId = setTimeout(() => {
emitter.emit(`onDelayedLoadPageResources`, { pathname })
apiRunner(`onRouteUpdateDelayed`, {
location: window.location,
})
}, 1000)

for plugins like gatsby-plugin-nprogress to show loader on page transitions

@marcysutton
Copy link
Contributor

What should we do with this PR @pieh?

@pieh
Copy link
Contributor Author

pieh commented Jun 5, 2019

What should we do with this PR @pieh?

Oh, hmm, if this didn't prove to be problem we can just discard this PR (if we will want to get back to it - I will keep branch around, tho it's pretty outdated at this point)

@pieh pieh closed this Jun 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants