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

♻️ Use JSS for video #30298

Merged
merged 13 commits into from
Sep 21, 2020
Merged

♻️ Use JSS for video #30298

merged 13 commits into from
Sep 21, 2020

Conversation

alanorozco
Copy link
Member

This is a port of video-autoplay.css.

No CSS def in an AMP component since there's not a PreactBaseElement that uses VideoWrapper yet.

Comment on lines 223 to 226
return [1, 2, 3, 4].map((i) => (
<div className={`${classes.eqCol} amp-video-eq-col`} key={i}>
<div className={`amp-video-eq-filler ${classes[`eq-${i}-1`]}`}></div>
<div className={`amp-video-eq-filler ${classes[`eq-${i}-2`]}`}></div>
Copy link
Member Author

Choose a reason for hiding this comment

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

@samouri Do I need to unwrap this loop since the member access for classes is dynamic?

Copy link
Member Author

Choose a reason for hiding this comment

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

(Current compiled output seems ok btw. In the future we could optimize this away as to not read classes, which would then break this.)

Copy link
Member

@samouri samouri Sep 18, 2020

Choose a reason for hiding this comment

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

Context: I have a PR coming up that converts the classes object to an enum.

You don't need to unroll the loop, but if you don't it'll deopt. I just tested it via the appspot closure compiler.

static access (unrolled)

// Source file
/** @enum {string} */
const a = { cx1: 'hello', cx2: 'world'};

console.log(a.cx1);
console.log(a.cx2)

// Compiled output
console.log("hello");
console.log("world");

dynamic access

// Source file
/** @enum {string} */
const a = { cx1: 'hello', cx2: 'world'};

[1,2].forEach(i => {
  console.log(a[`cx${i}`]);
})

// Compiled output
var a = {a:"hello", b:"world"};
[1, 2].forEach(function(b) {
  console.log(a["cx" + b]);
});

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, we wanted to make it fully enumerable so that it can be fully DCE'd to constants.

Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of unrolling, I wrote a compound selector. I believe it can be DCE'd now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or... the current solution to map only those classes one level above :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Or... just nth-child(x):before, :after :)

animationTimingFunction: 'linear',
animationIterationCount: 'infinite',
animationDirection: 'alternate',
backgroundColor: '#FAFAFA',
Copy link
Member

@samouri samouri Sep 18, 2020

Choose a reason for hiding this comment

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

i like the sound of this color 🎵

height: '100%',
position: 'absolute',
width: '100%',
willChange: 'transform',
Copy link
Member

Choose a reason for hiding this comment

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

FMI, do we have any data on the performance impact of using will-change?

Copy link
Member Author

Choose a reason for hiding this comment

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

No actual data. It does have an impact, since it definitely prevents some browsers from re-rendering when changing other CSS props.

const AutoplayIconContent = once(() => {
const classes = useAutoplayStyles();
return [1, 2, 3, 4].map((i) => (
<div className={`${classes.eqCol} amp-video-eq-col`} key={i}>
Copy link
Member

Choose a reason for hiding this comment

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

whats the point of keeping amp-video-eq-col? Should probably just use eqCol instead right (can also update the eqPlaying rule above)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Technically this element's style is overridable via this class. Though I'm not sure any author has gone that deep 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

Ok cool! Just making sure theres a reason. Do you know if this will live in the shadow or light dom? If lightdom then it is worth keeping as-is, if shadow then I'm not sure they can customize it via classname anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's using ['children'], so it's rendered in ShadowDOM. Though its children are cloned into VNodes, so we could move it to the light DOM. In any case, I think it's fine to remove access to amp-video-eq-col, but maybe not to amp-video-eq since that may be used to hide the equalizer...

Copy link
Contributor

@dvoytenko dvoytenko left a comment

Choose a reason for hiding this comment

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

IMHO this looks very clean.

@alanorozco alanorozco merged commit 71cd740 into ampproject:master Sep 21, 2020
@alanorozco alanorozco deleted the video-jss branch September 21, 2020 21:13
@alanorozco alanorozco mentioned this pull request Sep 22, 2020
17 tasks
ed-bird pushed a commit to ed-bird/amphtml that referenced this pull request Dec 10, 2020
This is a port of video-autoplay.css.

No CSS def in an AMP component since there's not a PreactBaseElement that uses VideoWrapper yet (see ampproject#30280)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants