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

[Demos] YouTube #87

Closed
addyosmani opened this issue Nov 2, 2019 · 19 comments
Closed

[Demos] YouTube #87

addyosmani opened this issue Nov 2, 2019 · 19 comments

Comments

@addyosmani
Copy link
Collaborator

addyosmani commented Nov 2, 2019

Description:

There's a neat YouTube demo implemented using React which allows you to see the homepage of videos, the watch page and search page.

I would like for us to make it a little smarter by:

📹 [P0] Video watch page: instead of loading the full embed-video component, we: check if you are on a slow network OR a low-memory device OR have low hardware concurrency and serve down a lighter custom element for the player instead (we may need to wrap it a little for use in React). We can use a similar pattern to network aware code-splitting, but add checks for memory and concurrency in the same boolean check within React.lazy().

🔗 [P0] Routing: Fix routing so that the links to https://marvtron.github.io/watch?v=GKXS_YA9s7E (etc) take you to https://marvtron.github.io/youtube-react/watch?v=GKXS_YA9s7E. Accessing https://marvtron.github.io/youtube-react/watch?v=GKXS_YA9s7E directly should load the video watch page.

🙊 [P1] On slow network or low-memory or low hardware-concurrency, don't load the comments widget and limit (by half) the number of results returned for the recommended videos:

image

🔧 [P0] I would like us to add the following code to the index so we can quickly show on the watch page which components are important vs not.

<script>
window.debug = () => {
   document.querySelector('.video-container').style.border = '15px solid green';
   document.querySelector('.related-videos').style.border = '15px solid red';
   document.querySelector("#root > div > div.watch-grid > div:nth-child(5)").style.border = '15px solid red';
};
</script>

🎨[P2] Take a quick look at whether render-blocking CSS can be optimized (e.g do we need all of semantic-ui?). I was reading through https://marvtron.github.io/youtube-react/static/css/2.20edb33d.chunk.css and at the very least, I think we don't need to load in the import for the Lato font. YouTube just uses Roboto if installed and I'm cool with us falling back to Arial without loading a Web Font (font-family: roboto, arial, sans-serif; )

I would say this is probably higher priority than ##63 for this week but could be looked at after #86 (#86, #87, #83, then #63).

cc @anton-karlovskiy

@anton-karlovskiy
Copy link
Contributor

anton-karlovskiy commented Nov 4, 2019

@addyosmani

Regarding [P0] Video watch page: instead of loading the full embed-video component, we: check if you are on a slow network OR a low-memory device OR have low hardware concurrency and serve down a lighter custom element for the player instead (we may need to wrap it a little for use in React). We can use a similar pattern to network aware code-splitting, but add checks for memory and concurrency in the same boolean check within React.lazy().

Should we not use hooks for memory and concurrency?
If we use hooks, we might not be able to use network aware code-splitting pattern because I think hooks are not available in React.lazy() async method. So I'd like to suggest that we could use network hook, memory hook, and concurrency hook.

@addyosmani
Copy link
Collaborator Author

Ultimately, I want us to use whichever option (hooks or the direct APIs) allows us to avoid sending down the extra code to users. It sounds like we should use hooks and can circle back if we need to rethink this.

If I remember correctly, using the hooks allows us to decide whether to show a heavy or light component but doesn't let us change what bundle gets loaded. Is that correct? We may be okay to use the hooks given the change is "are we using YouTube's iframe embed, that loads in a bunch of its own scripts vs using our own custom lazy-loading embedder?".

@anton-karlovskiy
Copy link
Contributor

@addyosmani

Thank you for your clarifying.
I've got your points. As for bundle loading by hooks, I think I should experiment once more as I thought it allows us to change what bundle gets loaded by webpack default configuration of create-react-app.
We can check it soon. I'm wrapping up this feature.

@addyosmani
Copy link
Collaborator Author

Awesome. Thanks, Anton!

@anton-karlovskiy
Copy link
Contributor

anton-karlovskiy commented Nov 5, 2019

@addyosmani

I've checked the bundle chunks for both lite and heavy mode.
heavy
lite

In my opinion, using hooks not only allows us to decide wether to show a heavy or light component but also let us control what bundle gets loaded according to the current deployed project.
So I think there is no significant difference in chunks loading if we just use hooks other than network code-splitting pattern.

Could you please confirm if this is correct?

@addyosmani
Copy link
Collaborator Author

That matches my thinking too. Let's move ahead using Hooks here... :)

@anton-karlovskiy
Copy link
Contributor

anton-karlovskiy commented Nov 6, 2019

@addyosmani

Because user changing the data-videoid attribute is not supported, dynamically setting the attribute is not working yet.
For example, just clicking on a video in the list does not properly open a video.

Capture

I think we should find an solution to it (Paul Irish might implement it soon or we might have to implement it ourselves).

@addyosmani
Copy link
Collaborator Author

addyosmani commented Nov 6, 2019 via email

@anton-karlovskiy
Copy link
Contributor

anton-karlovskiy commented Nov 8, 2019

@addyosmani

[P0] I would like us to add the following code to the index so we can quickly show on the watch page which components are important vs not.

<script>
window.debug = () => {
   document.querySelector('.video-container').style.border = '15px solid green';
   document.querySelector('.related-videos').style.border = '15px solid red';
   document.querySelector("#root > div > div.watch-grid > div:nth-child(5)").style.border = '15px solid red';
};
</script>

It's very weird because the script is loaded and working in local development mode.
local-dev

But after deployed to firebase, it's not loaded according to Chrome DevTools Elements tab.
Looking into view page source, it's there.

script-not-loaded

script-there-view-page-source

@addyosmani
Copy link
Collaborator Author

After taking a look at the latest commits, we could get by without working on the P2 (for now - unless you've started an implementation already?).

The demo as-is is pretty solid. With respect to the window.debug() issue we are running into, my current workflow is to paste the code for this into the DevTools console and just run it. Given this, I don't think it's worth us spending too much time looking at why this wasn't working.

@anton-karlovskiy
Copy link
Contributor

@addyosmani

Yes, as we discussed about that alternative with respect to window.debug(), I have not spent much time fixing it.
For P2 as well, I thought it was what we could circle back.

@anton-karlovskiy
Copy link
Contributor

anton-karlovskiy commented Nov 15, 2019

@addyosmani

#87 (comment)

FYI: Currently it's working for the version deployed on Firebase. It's weird as it would not work at the beginning.
Capture

@anton-karlovskiy
Copy link
Contributor

anton-karlovskiy commented Nov 15, 2019

@addyosmani

We just have [P2]. Shall I add this to the backlog and go ahead with this?

@addyosmani
Copy link
Collaborator Author

I think it's okay to skip the P2. Perhaps now is a good time to switch to the migration over to the react-adaptive-hooks project while waiting on extra microsite feedback?

@anton-karlovskiy
Copy link
Contributor

@addyosmani

This project is missing from the README of https://github.com/GoogleChromeLabs/react-adaptive-hooks.
Is this on purpose?

@anton-karlovskiy
Copy link
Contributor

I think it's okay to skip the P2. Perhaps now is a good time to switch to the migration over to the react-adaptive-hooks project while waiting on extra microsite feedback?

It's started. Right now I'm working on updating demos based on react-adaptive-hooks package.

@addyosmani
Copy link
Collaborator Author

addyosmani commented Nov 15, 2019 via email

@addyosmani
Copy link
Collaborator Author

@anton-karlovskiy Would you like to file a PR against the hooks project to add the YouTube app to the list of demos?

@anton-karlovskiy
Copy link
Contributor

@addyosmani

No problem. Let me handle.

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

No branches or pull requests

2 participants